Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/openssl/lib/libcrypto Add BN_oct2bn(3) f...



details:   https://anonhg.NetBSD.org/src/rev/ebd45501f53a
branches:  trunk
changeset: 940149:ebd45501f53a
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Oct 04 19:32:48 2020 +0000

description:
Add BN_oct2bn(3) for factor(6)

diffstat:

 crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c |  92 ++++++++++++++++++-
 crypto/external/bsd/openssl/dist/include/openssl/bn.h |   1 +
 crypto/external/bsd/openssl/lib/libcrypto/crypto.map  |   1 +
 3 files changed, 91 insertions(+), 3 deletions(-)

diffs (131 lines):

diff -r 6ff0ba413735 -r ebd45501f53a crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c
--- a/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c     Sun Oct 04 19:32:15 2020 +0000
+++ b/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c     Sun Oct 04 19:32:48 2020 +0000
@@ -266,6 +266,87 @@
     return 0;
 }
 
+int BN_oct2bn(BIGNUM **bn, const char *a)
+{
+    BIGNUM *ret = NULL;
+    BN_ULONG l = 0;
+    int neg = 0, h, m, i, j, b, k, c, r;
+    int num;
+
+    if (a == NULL || *a == '\0')
+        return 0;
+
+    if (*a == '-') {
+        neg = 1;
+        a++;
+    }
+
+    for (i = 0; i <= INT_MAX / 4 && ossl_isdigit(a[i]) && a[i] < '8'; i++)
+        continue;
+
+    if (i == 0 || i > INT_MAX / 4)
+        goto err;
+
+    num = i + neg;
+    if (bn == NULL)
+        return num;
+
+    /* a is the start of the hex digits, and it is 'i' long */
+    if (*bn == NULL) {
+        if ((ret = BN_new()) == NULL)
+            return 0;
+    } else {
+        ret = *bn;
+        BN_zero(ret);
+    }
+
+    /* i is the number of hex digits */
+    if (bn_expand(ret, i * 4) == NULL)
+        goto err;
+
+    j = i;                      /* least significant 'oct' */
+    h = 0;
+    b = 0;
+#define M (BN_BYTES * 8 / 3)
+    while (j > 0) {
+        m = (M <= j) ? M : j;
+       while (m > 0) {
+           k = a[j - m] - '0';
+           l = (l << 3) | k;
+           b += 3;
+           m--;
+       }
+        j -= M;
+       if (j <= 0) {
+           ret->d[h++] = l;
+           break;
+       }
+       b = BN_BYTES * 8 - b;
+       r = 3 - b;
+       k = a[j--] - '0';
+       l = (l << r) | (k >> b);
+       ret->d[h++] = l;
+       l = k & ((2 << r) - 1);
+       if (j == 0) {
+           ret->d[h++] = l;
+           break;
+       }
+    }
+    ret->top = h;
+    bn_correct_top(ret);
+
+    *bn = ret;
+    bn_check_top(ret);
+    /* Don't set the negative flag if it's zero. */
+    if (ret->top != 0)
+        ret->neg = neg;
+    return num;
+ err:
+    if (*bn == NULL)
+        BN_free(ret);
+    return 0;
+}
+
 int BN_asc2bn(BIGNUM **bn, const char *a)
 {
     const char *p = a;
@@ -273,9 +354,14 @@
     if (*p == '-')
         p++;
 
-    if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {
-        if (!BN_hex2bn(bn, p + 2))
-            return 0;
+    if (p[0] == '0') {
+       if (p[1] == 'X' || p[1] == 'x') {
+           if (!BN_hex2bn(bn, p + 2))
+               return 0;
+       } else {
+           if (!BN_oct2bn(bn, p + 1))
+               return 0;
+       }
     } else {
         if (!BN_dec2bn(bn, p))
             return 0;
diff -r 6ff0ba413735 -r ebd45501f53a crypto/external/bsd/openssl/dist/include/openssl/bn.h
--- a/crypto/external/bsd/openssl/dist/include/openssl/bn.h     Sun Oct 04 19:32:15 2020 +0000
+++ b/crypto/external/bsd/openssl/dist/include/openssl/bn.h     Sun Oct 04 19:32:48 2020 +0000
@@ -310,6 +310,7 @@
 char *BN_bn2dec(const BIGNUM *a);
 int BN_hex2bn(BIGNUM **a, const char *str);
 int BN_dec2bn(BIGNUM **a, const char *str);
+int BN_oct2bn(BIGNUM **a, const char *str);
 int BN_asc2bn(BIGNUM **a, const char *str);
 int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
 int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); /* returns
diff -r 6ff0ba413735 -r ebd45501f53a crypto/external/bsd/openssl/lib/libcrypto/crypto.map
--- a/crypto/external/bsd/openssl/lib/libcrypto/crypto.map      Sun Oct 04 19:32:15 2020 +0000
+++ b/crypto/external/bsd/openssl/lib/libcrypto/crypto.map      Sun Oct 04 19:32:48 2020 +0000
@@ -552,6 +552,7 @@
         BN_nnmod;
         BN_num_bits;
         BN_num_bits_word;
+       BN_oct2bn;
         BN_options;
         BN_print;
         BN_print_fp;



Home | Main Index | Thread Index | Old Index