Module Name: src
Committed By: christos
Date: Sun Oct 4 19:32:48 UTC 2020
Modified Files:
src/crypto/external/bsd/openssl/dist/crypto/bn: bn_print.c
src/crypto/external/bsd/openssl/dist/include/openssl: bn.h
src/crypto/external/bsd/openssl/lib/libcrypto: crypto.map
Log Message:
Add BN_oct2bn(3) for factor(6)
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.10 -r1.2 \
src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c
cvs rdiff -u -r1.1.1.3 -r1.2 \
src/crypto/external/bsd/openssl/dist/include/openssl/bn.h
cvs rdiff -u -r1.8 -r1.9 \
src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c
diff -u src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.1.1.10 src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.2
--- src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.1.1.10 Sat Mar 21 20:49:05 2020
+++ src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c Sun Oct 4 15:32:48 2020
@@ -266,6 +266,87 @@ int BN_dec2bn(BIGNUM **bn, const char *a
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 @@ int BN_asc2bn(BIGNUM **bn, const char *a
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;
Index: src/crypto/external/bsd/openssl/dist/include/openssl/bn.h
diff -u src/crypto/external/bsd/openssl/dist/include/openssl/bn.h:1.1.1.3 src/crypto/external/bsd/openssl/dist/include/openssl/bn.h:1.2
--- src/crypto/external/bsd/openssl/dist/include/openssl/bn.h:1.1.1.3 Sun Sep 23 09:17:50 2018
+++ src/crypto/external/bsd/openssl/dist/include/openssl/bn.h Sun Oct 4 15:32:48 2020
@@ -310,6 +310,7 @@ char *BN_bn2hex(const BIGNUM *a);
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
Index: src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map
diff -u src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map:1.8 src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map:1.9
--- src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map:1.8 Sat Mar 21 20:53:11 2020
+++ src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map Sun Oct 4 15:32:48 2020
@@ -552,6 +552,7 @@ OPENSSL_1_1_0 {
BN_nnmod;
BN_num_bits;
BN_num_bits_word;
+ BN_oct2bn;
BN_options;
BN_print;
BN_print_fp;