Lines Matching refs:bn
69 BIGNUM *bn = OPENSSL_malloc(sizeof(BIGNUM)); in BN_new() local
71 if (bn == NULL) { in BN_new()
76 OPENSSL_memset(bn, 0, sizeof(BIGNUM)); in BN_new()
77 bn->flags = BN_FLG_MALLOCED; in BN_new()
79 return bn; in BN_new()
82 void BN_init(BIGNUM *bn) { in BN_init() argument
83 OPENSSL_memset(bn, 0, sizeof(BIGNUM)); in BN_init()
86 void BN_free(BIGNUM *bn) { in BN_free() argument
87 if (bn == NULL) { in BN_free()
91 if ((bn->flags & BN_FLG_STATIC_DATA) == 0) { in BN_free()
92 OPENSSL_free(bn->d); in BN_free()
95 if (bn->flags & BN_FLG_MALLOCED) { in BN_free()
96 OPENSSL_free(bn); in BN_free()
98 bn->d = NULL; in BN_free()
102 void BN_clear_free(BIGNUM *bn) { in BN_clear_free() argument
105 if (bn == NULL) { in BN_clear_free()
109 if (bn->d != NULL) { in BN_clear_free()
110 OPENSSL_cleanse(bn->d, bn->dmax * sizeof(bn->d[0])); in BN_clear_free()
111 if ((bn->flags & BN_FLG_STATIC_DATA) == 0) { in BN_clear_free()
112 OPENSSL_free(bn->d); in BN_clear_free()
116 should_free = (bn->flags & BN_FLG_MALLOCED) != 0; in BN_clear_free()
117 OPENSSL_cleanse(bn, sizeof(BIGNUM)); in BN_clear_free()
119 OPENSSL_free(bn); in BN_clear_free()
159 void BN_clear(BIGNUM *bn) { in BN_clear() argument
160 if (bn->d != NULL) { in BN_clear()
161 OPENSSL_memset(bn->d, 0, bn->dmax * sizeof(bn->d[0])); in BN_clear()
164 bn->top = 0; in BN_clear()
165 bn->neg = 0; in BN_clear()
225 unsigned BN_num_bits(const BIGNUM *bn) { in BN_num_bits() argument
226 const int max = bn->top - 1; in BN_num_bits()
228 if (BN_is_zero(bn)) { in BN_num_bits()
232 return max*BN_BITS2 + BN_num_bits_word(bn->d[max]); in BN_num_bits()
235 unsigned BN_num_bytes(const BIGNUM *bn) { in BN_num_bytes() argument
236 return (BN_num_bits(bn) + 7) / 8; in BN_num_bytes()
239 void BN_zero(BIGNUM *bn) { in BN_zero() argument
240 bn->top = bn->neg = 0; in BN_zero()
243 int BN_one(BIGNUM *bn) { in BN_one() argument
244 return BN_set_word(bn, 1); in BN_one()
247 int BN_set_word(BIGNUM *bn, BN_ULONG value) { in BN_set_word() argument
249 BN_zero(bn); in BN_set_word()
253 if (bn_wexpand(bn, 1) == NULL) { in BN_set_word()
257 bn->neg = 0; in BN_set_word()
258 bn->d[0] = value; in BN_set_word()
259 bn->top = 1; in BN_set_word()
263 int BN_set_u64(BIGNUM *bn, uint64_t value) { in BN_set_u64() argument
265 return BN_set_word(bn, value); in BN_set_u64()
268 return BN_set_word(bn, (BN_ULONG)value); in BN_set_u64()
271 if (bn_wexpand(bn, 2) == NULL) { in BN_set_u64()
275 bn->neg = 0; in BN_set_u64()
276 bn->d[0] = (BN_ULONG)value; in BN_set_u64()
277 bn->d[1] = (BN_ULONG)(value >> 32); in BN_set_u64()
278 bn->top = 2; in BN_set_u64()
285 int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num) { in bn_set_words() argument
286 if (bn_wexpand(bn, num) == NULL) { in bn_set_words()
289 OPENSSL_memmove(bn->d, words, num * sizeof(BN_ULONG)); in bn_set_words()
291 bn->top = (int)num; in bn_set_words()
292 bn_correct_top(bn); in bn_set_words()
293 bn->neg = 0; in bn_set_words()
297 int BN_is_negative(const BIGNUM *bn) { in BN_is_negative() argument
298 return bn->neg != 0; in BN_is_negative()
301 void BN_set_negative(BIGNUM *bn, int sign) { in BN_set_negative() argument
302 if (sign && !BN_is_zero(bn)) { in BN_set_negative()
303 bn->neg = 1; in BN_set_negative()
305 bn->neg = 0; in BN_set_negative()
309 BIGNUM *bn_wexpand(BIGNUM *bn, size_t words) { in bn_wexpand() argument
312 if (words <= (size_t)bn->dmax) { in bn_wexpand()
313 return bn; in bn_wexpand()
321 if (bn->flags & BN_FLG_STATIC_DATA) { in bn_wexpand()
332 OPENSSL_memcpy(a, bn->d, sizeof(BN_ULONG) * bn->top); in bn_wexpand()
334 OPENSSL_free(bn->d); in bn_wexpand()
335 bn->d = a; in bn_wexpand()
336 bn->dmax = (int)words; in bn_wexpand()
338 return bn; in bn_wexpand()
341 BIGNUM *bn_expand(BIGNUM *bn, size_t bits) { in bn_expand() argument
346 return bn_wexpand(bn, (bits+BN_BITS2-1)/BN_BITS2); in bn_expand()
349 void bn_correct_top(BIGNUM *bn) { in bn_correct_top() argument
351 int tmp_top = bn->top; in bn_correct_top()
354 for (ftl = &(bn->d[tmp_top - 1]); tmp_top > 0; tmp_top--) { in bn_correct_top()
359 bn->top = tmp_top; in bn_correct_top()
362 if (bn->top == 0) { in bn_correct_top()
363 bn->neg = 0; in bn_correct_top()