Home | History | Annotate | Download | only in bn

Lines Matching defs:bn

57 #include <openssl/bn.h>
69 BIGNUM *bn = OPENSSL_malloc(sizeof(BIGNUM));
71 if (bn == NULL) {
72 OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
76 memset(bn, 0, sizeof(BIGNUM));
77 bn->flags = BN_FLG_MALLOCED;
79 return bn;
82 void BN_init(BIGNUM *bn) {
83 memset(bn, 0, sizeof(BIGNUM));
86 void BN_free(BIGNUM *bn) {
87 if (bn == NULL) {
91 if ((bn->flags & BN_FLG_STATIC_DATA) == 0) {
92 OPENSSL_free(bn->d);
95 if (bn->flags & BN_FLG_MALLOCED) {
96 OPENSSL_free(bn);
98 bn->d = NULL;
102 void BN_clear_free(BIGNUM *bn) {
105 if (bn == NULL) {
109 if (bn->d != NULL) {
110 OPENSSL_cleanse(bn->d, bn->dmax * sizeof(bn->d[0]));
111 if ((bn->flags & BN_FLG_STATIC_DATA) == 0) {
112 OPENSSL_free(bn->d);
116 should_free = (bn->flags & BN_FLG_MALLOCED) != 0;
117 OPENSSL_cleanse(bn, sizeof(BIGNUM));
119 OPENSSL_free(bn);
159 void BN_clear(BIGNUM *bn) {
160 if (bn->d != NULL) {
161 memset(bn->d, 0, bn->dmax * sizeof(bn->d[0]));
164 bn->top = 0;
165 bn->neg = 0;
231 unsigned BN_num_bits(const BIGNUM *bn) {
232 const int max = bn->top - 1;
234 if (BN_is_zero(bn)) {
238 return max*BN_BITS2 + BN_num_bits_word(bn->d[max]);
241 unsigned BN_num_bytes(const BIGNUM *bn) {
242 return (BN_num_bits(bn) + 7) / 8;
245 void BN_zero(BIGNUM *bn) {
246 bn->top = bn->neg = 0;
249 int BN_one(BIGNUM *bn) {
250 return BN_set_word(bn, 1);
253 int BN_set_word(BIGNUM *bn, BN_ULONG value) {
255 BN_zero(bn);
259 if (bn_wexpand(bn, 1) == NULL) {
263 bn->neg = 0;
264 bn->d[0] = value;
265 bn->top = 1;
269 int BN_is_negative(const BIGNUM *bn) {
270 return bn->neg != 0;
273 void BN_set_negative(BIGNUM *bn, int sign) {
274 if (sign && !BN_is_zero(bn)) {
275 bn->neg = 1;
277 bn->neg = 0;
281 BIGNUM *bn_wexpand(BIGNUM *bn, size_t words) {
284 if (words <= (size_t)bn->dmax) {
285 return bn;
289 OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
293 if (bn->flags & BN_FLG_STATIC_DATA) {
294 OPENSSL_PUT_ERROR(BN, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
300 OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
304 memcpy(a, bn->d, sizeof(BN_ULONG) * bn->top);
306 OPENSSL_free(bn->d);
307 bn->d = a;
308 bn->dmax = (int)words;
310 return bn;
313 BIGNUM *bn_expand(BIGNUM *bn, size_t bits) {
315 OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
318 return bn_wexpand(bn, (bits+BN_BITS2-1)/BN_BITS2);
321 void bn_correct_top(BIGNUM *bn) {
323 int tmp_top = bn->top;
326 for (ftl = &(bn->d[tmp_top - 1]); tmp_top > 0; tmp_top--) {
331 bn->top = tmp_top;
335 int BN_get_flags(const BIGNUM *bn, int flags) {
336 return bn->flags & flags;
339 void BN_set_flags(BIGNUM *bn, int flags) {
340 bn->flags |= flags;