• Home
  • Raw
  • Download

Lines Matching refs:bn

70   BIGNUM *bn = OPENSSL_malloc(sizeof(BIGNUM));  in BN_new()  local
72 if (bn == NULL) { in BN_new()
77 OPENSSL_memset(bn, 0, sizeof(BIGNUM)); in BN_new()
78 bn->flags = BN_FLG_MALLOCED; in BN_new()
80 return bn; in BN_new()
83 void BN_init(BIGNUM *bn) { in BN_init() argument
84 OPENSSL_memset(bn, 0, sizeof(BIGNUM)); in BN_init()
87 void BN_free(BIGNUM *bn) { in BN_free() argument
88 if (bn == NULL) { in BN_free()
92 if ((bn->flags & BN_FLG_STATIC_DATA) == 0) { in BN_free()
93 OPENSSL_free(bn->d); in BN_free()
96 if (bn->flags & BN_FLG_MALLOCED) { in BN_free()
97 OPENSSL_free(bn); in BN_free()
99 bn->d = NULL; in BN_free()
103 void BN_clear_free(BIGNUM *bn) { in BN_clear_free() argument
106 if (bn == NULL) { in BN_clear_free()
110 if (bn->d != NULL) { 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()
114 OPENSSL_cleanse(bn->d, bn->dmax * sizeof(bn->d[0])); in BN_clear_free()
118 should_free = (bn->flags & BN_FLG_MALLOCED) != 0; in BN_clear_free()
120 OPENSSL_free(bn); in BN_clear_free()
122 OPENSSL_cleanse(bn, sizeof(BIGNUM)); in BN_clear_free()
162 void BN_clear(BIGNUM *bn) { in BN_clear() argument
163 if (bn->d != NULL) { in BN_clear()
164 OPENSSL_memset(bn->d, 0, bn->dmax * sizeof(bn->d[0])); in BN_clear()
167 bn->width = 0; in BN_clear()
168 bn->neg = 0; in BN_clear()
235 unsigned BN_num_bits(const BIGNUM *bn) { in BN_num_bits() argument
236 const int width = bn_minimal_width(bn); in BN_num_bits()
241 return (width - 1) * BN_BITS2 + BN_num_bits_word(bn->d[width - 1]); in BN_num_bits()
244 unsigned BN_num_bytes(const BIGNUM *bn) { in BN_num_bytes() argument
245 return (BN_num_bits(bn) + 7) / 8; in BN_num_bytes()
248 void BN_zero(BIGNUM *bn) { in BN_zero() argument
249 bn->width = bn->neg = 0; in BN_zero()
252 int BN_one(BIGNUM *bn) { in BN_one() argument
253 return BN_set_word(bn, 1); in BN_one()
256 int BN_set_word(BIGNUM *bn, BN_ULONG value) { in BN_set_word() argument
258 BN_zero(bn); in BN_set_word()
262 if (!bn_wexpand(bn, 1)) { in BN_set_word()
266 bn->neg = 0; in BN_set_word()
267 bn->d[0] = value; in BN_set_word()
268 bn->width = 1; in BN_set_word()
272 int BN_set_u64(BIGNUM *bn, uint64_t value) { in BN_set_u64() argument
274 return BN_set_word(bn, value); in BN_set_u64()
277 return BN_set_word(bn, (BN_ULONG)value); in BN_set_u64()
280 if (!bn_wexpand(bn, 2)) { in BN_set_u64()
284 bn->neg = 0; in BN_set_u64()
285 bn->d[0] = (BN_ULONG)value; in BN_set_u64()
286 bn->d[1] = (BN_ULONG)(value >> 32); in BN_set_u64()
287 bn->width = 2; in BN_set_u64()
294 int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num) { in bn_set_words() argument
295 if (!bn_wexpand(bn, num)) { in bn_set_words()
298 OPENSSL_memmove(bn->d, words, num * sizeof(BN_ULONG)); in bn_set_words()
300 bn->width = (int)num; in bn_set_words()
301 bn->neg = 0; in bn_set_words()
305 int bn_fits_in_words(const BIGNUM *bn, size_t num) { in bn_fits_in_words() argument
308 for (size_t i = num; i < (size_t)bn->width; i++) { in bn_fits_in_words()
309 mask |= bn->d[i]; in bn_fits_in_words()
314 int bn_copy_words(BN_ULONG *out, size_t num, const BIGNUM *bn) { in bn_copy_words() argument
315 if (bn->neg) { in bn_copy_words()
320 size_t width = (size_t)bn->width; in bn_copy_words()
322 if (!bn_fits_in_words(bn, num)) { in bn_copy_words()
330 OPENSSL_memcpy(out, bn->d, sizeof(BN_ULONG) * width); in bn_copy_words()
334 int BN_is_negative(const BIGNUM *bn) { in BN_is_negative() argument
335 return bn->neg != 0; in BN_is_negative()
338 void BN_set_negative(BIGNUM *bn, int sign) { in BN_set_negative() argument
339 if (sign && !BN_is_zero(bn)) { in BN_set_negative()
340 bn->neg = 1; in BN_set_negative()
342 bn->neg = 0; in BN_set_negative()
346 int bn_wexpand(BIGNUM *bn, size_t words) { in bn_wexpand() argument
349 if (words <= (size_t)bn->dmax) { in bn_wexpand()
358 if (bn->flags & BN_FLG_STATIC_DATA) { in bn_wexpand()
369 OPENSSL_memcpy(a, bn->d, sizeof(BN_ULONG) * bn->width); in bn_wexpand()
371 OPENSSL_free(bn->d); in bn_wexpand()
372 bn->d = a; in bn_wexpand()
373 bn->dmax = (int)words; in bn_wexpand()
378 int bn_expand(BIGNUM *bn, size_t bits) { in bn_expand() argument
383 return bn_wexpand(bn, (bits+BN_BITS2-1)/BN_BITS2); in bn_expand()
386 int bn_resize_words(BIGNUM *bn, size_t words) { in bn_resize_words() argument
387 if ((size_t)bn->width <= words) { in bn_resize_words()
388 if (!bn_wexpand(bn, words)) { in bn_resize_words()
391 OPENSSL_memset(bn->d + bn->width, 0, in bn_resize_words()
392 (words - bn->width) * sizeof(BN_ULONG)); in bn_resize_words()
393 bn->width = words; in bn_resize_words()
398 if (!bn_fits_in_words(bn, words)) { in bn_resize_words()
402 bn->width = words; in bn_resize_words()
415 int bn_minimal_width(const BIGNUM *bn) { in bn_minimal_width() argument
416 int ret = bn->width; in bn_minimal_width()
417 while (ret > 0 && bn->d[ret - 1] == 0) { in bn_minimal_width()
423 void bn_set_minimal_width(BIGNUM *bn) { in bn_set_minimal_width() argument
424 bn->width = bn_minimal_width(bn); in bn_set_minimal_width()
425 if (bn->width == 0) { in bn_set_minimal_width()
426 bn->neg = 0; in bn_set_minimal_width()