Skip to content

Commit 2364778

Browse files
committed
prefix the MPI related macros with ltc_
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 3cc7546 commit 2364778

93 files changed

Lines changed: 1117 additions & 1120 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demos/timing.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ static void time_mult(void)
528528
if (ltc_mp.name == NULL) return;
529529

530530
fprintf(stderr, "Timing Multiplying:\n");
531-
mp_init_multi(&a,&b,&c,NULL);
532-
for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
533-
mp_rand(a, x);
534-
mp_rand(b, x);
531+
ltc_mp_init_multi(&a,&b,&c,NULL);
532+
for (x = 128/LTC_MP_DIGIT_BIT; x <= (unsigned long)1536/LTC_MP_DIGIT_BIT; x += 128/LTC_MP_DIGIT_BIT) {
533+
ltc_mp_rand(a, x);
534+
ltc_mp_rand(b, x);
535535

536-
#define DO1 mp_mul(a, b, c);
536+
#define DO1 ltc_mp_mul(a, b, c);
537537
#define DO2 DO1; DO1;
538538

539539
t2 = -1;
@@ -544,9 +544,9 @@ static void time_mult(void)
544544
t1 = (t_read() - t1)>>1;
545545
if (t1 < t2) t2 = t1;
546546
}
547-
fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2);
547+
fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*LTC_MP_DIGIT_BIT, t2);
548548
}
549-
mp_clear_multi(a,b,c,NULL);
549+
ltc_mp_deinit_multi(a,b,c,NULL);
550550

551551
#undef DO1
552552
#undef DO2
@@ -561,11 +561,11 @@ static void time_sqr(void)
561561
if (ltc_mp.name == NULL) return;
562562

563563
fprintf(stderr, "Timing Squaring:\n");
564-
mp_init_multi(&a,&b,NULL);
565-
for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
566-
mp_rand(a, x);
564+
ltc_mp_init_multi(&a,&b,NULL);
565+
for (x = 128/LTC_MP_DIGIT_BIT; x <= (unsigned long)1536/LTC_MP_DIGIT_BIT; x += 128/LTC_MP_DIGIT_BIT) {
566+
ltc_mp_rand(a, x);
567567

568-
#define DO1 mp_sqr(a, b);
568+
#define DO1 ltc_mp_sqr(a, b);
569569
#define DO2 DO1; DO1;
570570

571571
t2 = -1;
@@ -576,9 +576,9 @@ static void time_sqr(void)
576576
t1 = (t_read() - t1)>>1;
577577
if (t1 < t2) t2 = t1;
578578
}
579-
fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2);
579+
fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*LTC_MP_DIGIT_BIT, t2);
580580
}
581-
mp_clear_multi(a,b,NULL);
581+
ltc_mp_deinit_multi(a,b,NULL);
582582

583583
#undef DO1
584584
#undef DO2

demos/tv_gen.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -670,31 +670,31 @@ static void ecc_gen(void)
670670
fprintf(out, "ecc vectors. These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n");
671671
G = ltc_ecc_new_point();
672672
R = ltc_ecc_new_point();
673-
mp_init(&k);
674-
mp_init(&order);
675-
mp_init(&modulus);
676-
mp_init(&a);
673+
ltc_mp_init(&k);
674+
ltc_mp_init(&order);
675+
ltc_mp_init(&modulus);
676+
ltc_mp_init(&a);
677677

678678
for (x = 0; ltc_ecc_curves[x].prime != NULL; x++) {
679679
fprintf(out, "%s\n", ltc_ecc_curves[x].OID);
680-
mp_set(k, 1);
680+
ltc_mp_set(k, 1);
681681

682-
mp_read_radix(order, ltc_ecc_curves[x].order, 16);
683-
mp_read_radix(modulus, ltc_ecc_curves[x].prime, 16);
684-
mp_read_radix(a, ltc_ecc_curves[x].A, 16);
685-
mp_read_radix(G->x, ltc_ecc_curves[x].Gx, 16);
686-
mp_read_radix(G->y, ltc_ecc_curves[x].Gy, 16);
687-
mp_set(G->z, 1);
682+
ltc_mp_read_radix(order, ltc_ecc_curves[x].order, 16);
683+
ltc_mp_read_radix(modulus, ltc_ecc_curves[x].prime, 16);
684+
ltc_mp_read_radix(a, ltc_ecc_curves[x].A, 16);
685+
ltc_mp_read_radix(G->x, ltc_ecc_curves[x].Gx, 16);
686+
ltc_mp_read_radix(G->y, ltc_ecc_curves[x].Gy, 16);
687+
ltc_mp_set(G->z, 1);
688688

689-
while (mp_cmp(k, order) == LTC_MP_LT) {
689+
while (ltc_mp_cmp(k, order) == LTC_MP_LT) {
690690
ltc_mp.ecc_ptmul(k, G, R, a, modulus, 1);
691-
mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str);
692-
mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
693-
mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
694-
mp_mul_d(k, 3, k);
691+
ltc_mp_tohex(k, (char*)str); fprintf(out, "%s, ", (char*)str);
692+
ltc_mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
693+
ltc_mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
694+
ltc_mp_mul_d(k, 3, k);
695695
}
696696
}
697-
mp_clear_multi(k, order, modulus, a, LTC_NULL);
697+
ltc_mp_deinit_multi(k, order, modulus, a, LTC_NULL);
698698
ltc_ecc_del_point(G);
699699
ltc_ecc_del_point(R);
700700
fclose(out);

src/headers/tomcrypt_math.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ typedef struct {
502502

503503
extern ltc_math_descriptor ltc_mp;
504504

505-
int ltc_init_multi(void **a, ...) LTC_NULL_TERMINATED;
506-
void ltc_deinit_multi(void *a, ...) LTC_NULL_TERMINATED;
507-
void ltc_cleanup_multi(void **a, ...) LTC_NULL_TERMINATED;
505+
int ltc_mp_init_multi(void **a, ...) LTC_NULL_TERMINATED;
506+
void ltc_mp_deinit_multi(void *a, ...) LTC_NULL_TERMINATED;
507+
void ltc_mp_cleanup_multi(void **a, ...) LTC_NULL_TERMINATED;
508508

509509
#ifdef LTM_DESC
510510
extern const ltc_math_descriptor ltm_desc;

src/headers/tomcrypt_private.h

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -175,72 +175,69 @@ int omac_vprocess(omac_state *omac, const unsigned char *in, unsigned long inle
175175

176176
#if !defined(DESC_DEF_ONLY)
177177

178-
#define MP_DIGIT_BIT ltc_mp.bits_per_digit
178+
#define LTC_MP_DIGIT_BIT ltc_mp.bits_per_digit
179179

180180
/* some handy macros */
181-
#define mp_init(a) ltc_mp.init(a)
182-
#define mp_init_multi ltc_init_multi
183-
#define mp_clear(a) ltc_mp.deinit(a)
184-
#define mp_clear_multi ltc_deinit_multi
185-
#define mp_cleanup_multi ltc_cleanup_multi
186-
#define mp_init_copy(a, b) ltc_mp.init_copy(a, b)
187-
188-
#define mp_neg(a, b) ltc_mp.neg(a, b)
189-
#define mp_copy(a, b) ltc_mp.copy(a, b)
190-
191-
#define mp_set(a, b) ltc_mp.set_int(a, b)
192-
#define mp_set_int(a, b) ltc_mp.set_int(a, b)
193-
#define mp_get_int(a) ltc_mp.get_int(a)
194-
#define mp_get_digit(a, n) ltc_mp.get_digit(a, n)
195-
#define mp_get_digit_count(a) ltc_mp.get_digit_count(a)
196-
#define mp_cmp(a, b) ltc_mp.compare(a, b)
197-
#define mp_cmp_d(a, b) ltc_mp.compare_d(a, b)
198-
#define mp_count_bits(a) ltc_mp.count_bits(a)
199-
#define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a)
200-
#define mp_2expt(a, b) ltc_mp.twoexpt(a, b)
201-
202-
#define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c)
203-
#define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c)
204-
#define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a)
205-
#define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b)
206-
#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
207-
208-
#define mp_add(a, b, c) ltc_mp.add(a, b, c)
209-
#define mp_add_d(a, b, c) ltc_mp.addi(a, b, c)
210-
#define mp_sub(a, b, c) ltc_mp.sub(a, b, c)
211-
#define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c)
212-
#define mp_mul(a, b, c) ltc_mp.mul(a, b, c)
213-
#define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
214-
#define mp_sqr(a, b) ltc_mp.sqr(a, b)
215-
#define mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c)
216-
#define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
217-
#define mp_div_2(a, b) ltc_mp.div_2(a, b)
218-
#define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
219-
#define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
220-
#define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
221-
#define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
222-
223-
#define mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d)
224-
#define mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d)
225-
#define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
226-
#define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
227-
#define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
228-
229-
#define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
230-
#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
231-
#define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c)
232-
#define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a)
233-
234-
#define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d)
235-
#define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c)
236-
237-
#define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
238-
#define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
239-
#define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0)
240-
241-
#define mp_tohex(a, b) mp_toradix(a, b, 16)
242-
243-
#define mp_rand(a, b) ltc_mp.rand(a, b)
181+
#define ltc_mp_init(a) ltc_mp.init(a)
182+
#define ltc_mp_clear(a) ltc_mp.deinit(a)
183+
#define ltc_mp_init_copy(a, b) ltc_mp.init_copy(a, b)
184+
185+
#define ltc_mp_neg(a, b) ltc_mp.neg(a, b)
186+
#define ltc_mp_copy(a, b) ltc_mp.copy(a, b)
187+
188+
#define ltc_mp_set(a, b) ltc_mp.set_int(a, b)
189+
#define ltc_mp_set_int(a, b) ltc_mp.set_int(a, b)
190+
#define ltc_mp_get_int(a) ltc_mp.get_int(a)
191+
#define ltc_mp_get_digit(a, n) ltc_mp.get_digit(a, n)
192+
#define ltc_mp_get_digit_count(a) ltc_mp.get_digit_count(a)
193+
#define ltc_mp_cmp(a, b) ltc_mp.compare(a, b)
194+
#define ltc_mp_cmp_d(a, b) ltc_mp.compare_d(a, b)
195+
#define ltc_mp_count_bits(a) ltc_mp.count_bits(a)
196+
#define ltc_mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a)
197+
#define ltc_mp_2expt(a, b) ltc_mp.twoexpt(a, b)
198+
199+
#define ltc_mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c)
200+
#define ltc_mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c)
201+
#define ltc_mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a)
202+
#define ltc_mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b)
203+
#define ltc_mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
204+
205+
#define ltc_mp_add(a, b, c) ltc_mp.add(a, b, c)
206+
#define ltc_mp_add_d(a, b, c) ltc_mp.addi(a, b, c)
207+
#define ltc_mp_sub(a, b, c) ltc_mp.sub(a, b, c)
208+
#define ltc_mp_sub_d(a, b, c) ltc_mp.subi(a, b, c)
209+
#define ltc_mp_mul(a, b, c) ltc_mp.mul(a, b, c)
210+
#define ltc_mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
211+
#define ltc_mp_sqr(a, b) ltc_mp.sqr(a, b)
212+
#define ltc_mp_sqrtmod_prime(a, b, c) ltc_mp.sqrtmod_prime(a, b, c)
213+
#define ltc_mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
214+
#define ltc_mp_div_2(a, b) ltc_mp.div_2(a, b)
215+
#define ltc_mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
216+
#define ltc_mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
217+
#define ltc_mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
218+
#define ltc_mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
219+
220+
#define ltc_mp_addmod(a, b, c, d) ltc_mp.addmod(a, b, c, d)
221+
#define ltc_mp_submod(a, b, c, d) ltc_mp.submod(a, b, c, d)
222+
#define ltc_mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
223+
#define ltc_mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
224+
#define ltc_mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
225+
226+
#define ltc_mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
227+
#define ltc_mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
228+
#define ltc_mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c)
229+
#define ltc_mp_montgomery_free(a) ltc_mp.montgomery_deinit(a)
230+
231+
#define ltc_mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d)
232+
#define ltc_mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, b, c)
233+
234+
#define ltc_mp_iszero(a) (ltc_mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
235+
#define ltc_mp_isodd(a) (ltc_mp_get_digit_count(a) > 0 ? (ltc_mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
236+
#define ltc_mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0)
237+
238+
#define ltc_mp_tohex(a, b) ltc_mp_toradix(a, b, 16)
239+
240+
#define ltc_mp_rand(a, b) ltc_mp.rand(a, b)
244241

245242
#endif
246243

0 commit comments

Comments
 (0)