comparison bignum.c @ 1409:c721e8c42d2a

add m_mp_free_multi, be more careful freeing when failing to load keys
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 May 2017 21:08:43 +0800
parents 2bb4c662d1c2
children 1051e4eea25a
comparison
equal deleted inserted replaced
1407:8d9bad0a1c86 1409:c721e8c42d2a
66 cur_arg = va_arg(args, mp_int**); 66 cur_arg = va_arg(args, mp_int**);
67 } 67 }
68 va_end(args); 68 va_end(args);
69 } 69 }
70 70
71 void m_mp_free_multi(mp_int **mp, ...)
72 {
73 mp_int** cur_arg = mp;
74 va_list args;
75
76 va_start(args, mp); /* init args to next argument from caller */
77 while (cur_arg != NULL) {
78 if (*cur_arg) {
79 mp_clear(*cur_arg);
80 }
81 m_free(*cur_arg);
82 cur_arg = va_arg(args, mp_int**);
83 }
84 va_end(args);
85 }
86
71 void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) { 87 void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
72 88
73 if (mp_read_unsigned_bin(mp, (unsigned char*)bytes, len) != MP_OKAY) { 89 if (mp_read_unsigned_bin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
74 dropbear_exit("Mem alloc error"); 90 dropbear_exit("Mem alloc error");
75 } 91 }