123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #include "includes.h"
- #include "dbutil.h"
- void m_mp_init(mp_int *mp) {
- if (mp_init(mp) != MP_OKAY) {
- dropbear_exit("Mem alloc error");
- }
- }
- void m_mp_init_multi(mp_int *mp, ...)
- {
- mp_int* cur_arg = mp;
- va_list args;
- va_start(args, mp);
- while (cur_arg != NULL) {
- if (mp_init(cur_arg) != MP_OKAY) {
- dropbear_exit("Mem alloc error");
- }
- cur_arg = va_arg(args, mp_int*);
- }
- va_end(args);
- }
- void m_mp_alloc_init_multi(mp_int **mp, ...)
- {
- mp_int** cur_arg = mp;
- va_list args;
- va_start(args, mp);
- while (cur_arg != NULL) {
- *cur_arg = m_malloc(sizeof(mp_int));
- if (mp_init(*cur_arg) != MP_OKAY) {
- dropbear_exit("Mem alloc error");
- }
- cur_arg = va_arg(args, mp_int**);
- }
- va_end(args);
- }
- void m_mp_free_multi(mp_int **mp, ...)
- {
- mp_int** cur_arg = mp;
- va_list args;
- va_start(args, mp);
- while (cur_arg != NULL) {
- if (*cur_arg) {
- mp_clear(*cur_arg);
- }
- m_free(*cur_arg);
- cur_arg = va_arg(args, mp_int**);
- }
- va_end(args);
- }
- void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
- if (mp_from_ubin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
- dropbear_exit("Mem alloc error");
- }
- }
- void hash_process_mp(const struct ltc_hash_descriptor *hash_desc,
- hash_state *hs, mp_int *mp) {
- buffer * buf;
- buf = buf_new(512 + 20);
- buf_putmpint(buf, mp);
- hash_desc->process(hs, buf->data, buf->len);
- buf_burn_free(buf);
- }
|