summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2001-10-02 18:29:43 +0000
committerjbj <devnull@localhost>2001-10-02 18:29:43 +0000
commit105dbc3c83dc569cc46f5ff76bc154cda9e6e015 (patch)
tree1fa073d2e395f7bba48bc62c1e9ae1dda45c707c
parentc91fc958592f719722f116883f24613cc090a2f9 (diff)
downloadrpm-105dbc3c83dc569cc46f5ff76bc154cda9e6e015.tar.gz
rpm-105dbc3c83dc569cc46f5ff76bc154cda9e6e015.tar.bz2
rpm-105dbc3c83dc569cc46f5ff76bc154cda9e6e015.zip
Add b32bswabhex/mp32nswabhex.
CVS patchset: 5092 CVS date: 2001/10/02 18:29:43
-rw-r--r--beecrypt/mp32barrett.c68
-rw-r--r--beecrypt/mp32barrett.h6
-rw-r--r--beecrypt/mp32number.c52
-rw-r--r--beecrypt/mp32number.h6
4 files changed, 128 insertions, 4 deletions
diff --git a/beecrypt/mp32barrett.c b/beecrypt/mp32barrett.c
index 86c898274..438d07750 100644
--- a/beecrypt/mp32barrett.c
+++ b/beecrypt/mp32barrett.c
@@ -2,15 +2,14 @@
* \file mp32barrett.c
*
* Barrett modular reduction, code.
- */
-
-/*
*
* For more information on this algorithm, see:
* "Handbook of Applied Cryptography", Chapter 14.3.3
* Menezes, van Oorschot, Vanstone
* CRC Press
- *
+ */
+
+/*
* Copyright (c) 1997, 1998, 1999, 2000, 2001 Virtual Unlimited B.V.
*
* Author: Bob Deblier <bob@virtualunlimited.com>
@@ -227,6 +226,67 @@ void mp32bsethex(mp32barrett* b, const char* hex)
}
/*@=nullstate =compdef @*/
+/*@-nullstate -compdef @*/ /* b->modl may be null @*/
+void mp32bswabhex(mp32barrett* b, const char* hex)
+{
+ uint32 length = strlen(hex);
+ uint32 size = (length+7) >> 3;
+ uint8 rem = (uint8)(length & 0x7);
+
+ if (b->modl)
+ {
+ if (b->size != size)
+ b->modl = (uint32*) realloc(b->modl, (2*size+1) * sizeof(uint32));
+ }
+ else
+ b->modl = (uint32*) malloc((2*size+1) * sizeof(uint32));
+
+ if (b->modl != (uint32*) 0)
+ {
+ register uint32 val = 0;
+ register uint32* dst = b->modl;
+ register uint32* temp = (uint32*) malloc((6*size+4) * sizeof(uint32));
+ register char ch;
+
+ b->size = size;
+ b->mu = b->modl+size;
+
+ while (length-- > 0)
+ {
+ ch = *(hex++);
+ val <<= 4;
+ if (ch >= '0' && ch <= '9')
+ val += (ch - '0');
+ else if (ch >= 'A' && ch <= 'F')
+ val += (ch - 'A') + 10;
+ else if (ch >= 'a' && ch <= 'f')
+ val += (ch - 'a') + 10;
+ else
+ {};
+
+ if ((length & 0x7) == 0)
+ {
+ *(dst++) = swapu32(val);
+ val = 0;
+ }
+ }
+ if (rem != 0)
+ *dst = swapu32(val);
+
+ /*@-nullpass@*/ /* temp may be NULL */
+ mp32bmu_w(b, temp);
+
+ free(temp);
+ /*@=nullpass@*/
+ }
+ else
+ {
+ b->size = 0;
+ b->mu = 0;
+ }
+}
+/*@=nullstate =compdef @*/
+
/**
* Computes the Barrett 'mu' coefficient.
* needs workspace of (6*size+4) words
diff --git a/beecrypt/mp32barrett.h b/beecrypt/mp32barrett.h
index 8b8a5660d..0b77987bf 100644
--- a/beecrypt/mp32barrett.h
+++ b/beecrypt/mp32barrett.h
@@ -82,6 +82,12 @@ void mp32bsethex(mp32barrett* b, const char* hex)
/**
*/
+BEEDLLAPI /*@unused@*/
+void mp32bswabhex(mp32barrett* b, const char* hex)
+ /*@modifies b->size, b->modl, b->mu @*/;
+
+/**
+ */
BEEDLLAPI
void mp32bsubone(const mp32barrett* b, uint32* result)
/*@modifies result @*/;
diff --git a/beecrypt/mp32number.c b/beecrypt/mp32number.c
index a4c766de7..3cd97558c 100644
--- a/beecrypt/mp32number.c
+++ b/beecrypt/mp32number.c
@@ -229,3 +229,55 @@ void mp32nsethex(mp32number* n, const char* hex)
}
}
/*@=nullstate =compdef @*/
+
+/*@-nullstate -compdef @*/ /* n->data may be NULL */
+void mp32nswabhex(mp32number* n, const char* hex)
+{
+ uint32 length = strlen(hex);
+ uint32 size = (length+7) >> 3;
+ uint8 rem = (uint8)(length & 0x7);
+
+ if (n->data)
+ {
+ if (n->size != size)
+ n->data = (uint32*) realloc(n->data, size * sizeof(uint32));
+ }
+ else
+ n->data = (uint32*) malloc(size * sizeof(uint32));
+
+ if (n->data)
+ {
+ register uint32 val = 0;
+ register uint32* dst = n->data;
+ register char ch;
+
+ n->size = size;
+
+ while (length-- > 0)
+ {
+ ch = *(hex++);
+ val <<= 4;
+ if (ch >= '0' && ch <= '9')
+ val += (ch - '0');
+ else if (ch >= 'A' && ch <= 'F')
+ val += (ch - 'A') + 10;
+ else if (ch >= 'a' && ch <= 'f')
+ val += (ch - 'a') + 10;
+ else
+ {};
+
+ if ((length & 0x7) == 0)
+ {
+ *(dst++) = swapu32(val);
+ val = 0;
+ }
+ }
+ if (rem != 0)
+ *dst = swapu32(val);
+ }
+ else {
+ n->size = 0;
+ n->data = (uint32*)0;
+ }
+}
+/*@=nullstate =compdef @*/
diff --git a/beecrypt/mp32number.h b/beecrypt/mp32number.h
index f2cfc2b15..d091fff65 100644
--- a/beecrypt/mp32number.h
+++ b/beecrypt/mp32number.h
@@ -98,6 +98,12 @@ BEEDLLAPI /*@unused@*/
void mp32nsethex(mp32number* n, const char* hex)
/*@modifies n->size, n->data @*/;
+/**
+ */
+BEEDLLAPI /*@unused@*/
+void mp32nswabhex(mp32number* n, const char* hex)
+ /*@modifies n->size, n->data @*/;
+
#ifdef __cplusplus
}
#endif