comparison ecc.c @ 805:724c3e0c8734 ecc

Add m_mp_alloc_init_multi() helper
author Matt Johnston <matt@ucc.asn.au>
date Thu, 23 May 2013 22:18:16 +0800
parents 70625eed40c9
children 7540c0822374
comparison
equal deleted inserted replaced
804:34b73c9d8aa3 805:724c3e0c8734
70 return *curve; 70 return *curve;
71 } 71 }
72 72
73 ecc_key * new_ecc_key(void) { 73 ecc_key * new_ecc_key(void) {
74 ecc_key *key = m_malloc(sizeof(*key)); 74 ecc_key *key = m_malloc(sizeof(*key));
75 key->pubkey.x = m_malloc(sizeof(mp_int)); 75 m_mp_alloc_init_multi(&key->pubkey.x, &key->pubkey.y,
76 key->pubkey.y = m_malloc(sizeof(mp_int)); 76 &key->pubkey.z, &key->k, NULL);
77 key->pubkey.z = m_malloc(sizeof(mp_int));
78 key->k = m_malloc(sizeof(mp_int));
79 m_mp_init_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
80 return key; 77 return key;
81 } 78 }
82 79
83 // Copied from libtomcrypt ecc_import.c (version there is static), modified 80 // Copied from libtomcrypt ecc_import.c (version there is static), modified
84 // for different mp_int pointer without LTC_SOURCE 81 // for different mp_int pointer without LTC_SOURCE
90 prime = m_malloc(sizeof(mp_int)); 87 prime = m_malloc(sizeof(mp_int));
91 b = m_malloc(sizeof(mp_int)); 88 b = m_malloc(sizeof(mp_int));
92 t1 = m_malloc(sizeof(mp_int)); 89 t1 = m_malloc(sizeof(mp_int));
93 t2 = m_malloc(sizeof(mp_int)); 90 t2 = m_malloc(sizeof(mp_int));
94 91
95 m_mp_init_multi(prime, b, t1, t2, NULL); 92 m_mp_alloc_init_multi(&prime, &b, &t1, &t2, NULL);
96 93
97 /* load prime and b */ 94 /* load prime and b */
98 if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK) { goto error; } 95 if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK) { goto error; }
99 if ((err = mp_read_radix(b, key->dp->B, 16)) != CRYPT_OK) { goto error; } 96 if ((err = mp_read_radix(b, key->dp->B, 16)) != CRYPT_OK) { goto error; }
100 97