If a binary sequence is all zero's, call BN_zero.
Reviewed-by: Matt Caswell <matt@openssl.org>
if (ret == NULL)
return (NULL);
bn_check_top(ret);
- l = 0;
+ /* Skip leading zero's. */
+ for ( ; *s == 0 && len > 0; s++, len--)
+ continue;
n = len;
if (n == 0) {
ret->top = 0;
}
ret->top = i;
ret->neg = 0;
+ l = 0;
while (n--) {
l = (l << 8L) | *(s++);
if (m-- == 0) {
ukm_be[7 - i] = ukm[i];
}
BN_CTX_start(ctx);
- UKM = getbnfrombuf(ukm_be, 8);
+ UKM = BN_bin2bn(ukm_be, 8, NULL);
p = BN_CTX_get(ctx);
order = BN_CTX_get(ctx);
X = BN_CTX_get(ctx);
rev_buf[31 - i] = s->data[i];
}
ASN1_STRING_free(s);
- pk_num = getbnfrombuf(rev_buf, 32);
+ pk_num = BN_bin2bn(rev_buf, 32, NULL);
} else {
priv_key = d2i_ASN1_INTEGER(NULL, &p, priv_len);
if (!priv_key)
len = octet->length / 2;
ASN1_OCTET_STRING_free(octet);
- Y = getbnfrombuf(databuf, len);
- X = getbnfrombuf(databuf + len, len);
+ Y = BN_bin2bn(databuf, len, NULL);
+ X = BN_bin2bn(databuf + len, len, NULL);
OPENSSL_free(databuf);
pub_key = EC_POINT_new(group);
if (!EC_POINT_set_affine_coordinates_GFp(group, pub_key, X, Y, NULL)) {
ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
-
-/* Convert byte buffer to bignum, skipping leading zeros*/
-BIGNUM *getbnfrombuf(const unsigned char *buf, size_t len)
-{
- BIGNUM *b;
-
- while (*buf == 0 && len > 0) {
- buf++;
- len--;
- }
- if (len)
- return BN_bin2bn(buf, len, NULL);
- b = BN_new();
- BN_zero(b);
- return b;
-}
* nesseccary
*/
int store_bignum(BIGNUM *bn, unsigned char *buf, int len);
-/* Read bignum, which can have few MSB all-zeros from buffer*/
-BIGNUM *getbnfrombuf(const unsigned char *buf, size_t len);
/* Pack GOST R 34.10 signature according to CryptoPro rules */
int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen);
/* Unpack GOST R 34.10 signature according to CryptoPro rules */