Error checking and memory leak fixes in NISTZ256.
[openssl.git] / crypto / bn / bn_intern.c
index cf2b33630e1a6037b9357abd6b491b3b922187fa..32ad50523d5937135ae538131cdf382c2623f597 100644 (file)
@@ -233,11 +233,20 @@ void bn_set_static_words(BIGNUM *a, BN_ULONG *words, int size)
     a->dmax = a->top = size;
     a->neg = 0;
     a->flags |= BN_FLG_STATIC_DATA;
+    bn_correct_top(a);
 }
 
-void bn_set_data(BIGNUM *a, const void *data, size_t size)
+int bn_set_words(BIGNUM *a, BN_ULONG *words, int num_words)
 {
-    memcpy(a->d, data, size);
+    if (bn_wexpand(a, num_words) == NULL) {
+        BNerr(BN_F_BN_SET_WORDS, ERR_R_MALLOC_FAILURE);
+        return 0;
+    }
+
+    memcpy(a->d, words, sizeof(BN_ULONG) * num_words);
+    a->top = num_words;
+    bn_correct_top(a);
+    return 1;
 }
 
 size_t bn_sizeof_BIGNUM(void)