Commit e45f75fddbeee1f900bc3d2a84a8f5559890f0b7

Daniel Mendler 2019-04-13T08:46:57

deprecate DIGIT_BIT, use MP_DIGIT_BIT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
diff --git a/bn_mp_2expt.c b/bn_mp_2expt.c
index 748088e..2b669da 100644
--- a/bn_mp_2expt.c
+++ b/bn_mp_2expt.c
@@ -16,15 +16,15 @@ int mp_2expt(mp_int *a, int b)
    mp_zero(a);
 
    /* grow a to accomodate the single bit */
-   if ((res = mp_grow(a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
+   if ((res = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
       return res;
    }
 
    /* set the used count of where the bit will go */
-   a->used = (b / DIGIT_BIT) + 1;
+   a->used = (b / MP_DIGIT_BIT) + 1;
 
    /* put the single bit in its place */
-   a->dp[b / DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % DIGIT_BIT);
+   a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);
 
    return MP_OKAY;
 }
diff --git a/bn_mp_add_d.c b/bn_mp_add_d.c
index fe6e068..9b408c4 100644
--- a/bn_mp_add_d.c
+++ b/bn_mp_add_d.c
@@ -49,13 +49,13 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
        * the carry.
        */
       *tmpc   = *tmpa++ + b;
-      mu      = *tmpc >> DIGIT_BIT;
+      mu      = *tmpc >> MP_DIGIT_BIT;
       *tmpc++ &= MP_MASK;
 
       /* now handle rest of the digits */
       for (ix = 1; ix < a->used; ix++) {
          *tmpc   = *tmpa++ + mu;
-         mu      = *tmpc >> DIGIT_BIT;
+         mu      = *tmpc >> MP_DIGIT_BIT;
          *tmpc++ &= MP_MASK;
       }
       /* set final carry */
diff --git a/bn_mp_cnt_lsb.c b/bn_mp_cnt_lsb.c
index ceae48a..4b2d206 100644
--- a/bn_mp_cnt_lsb.c
+++ b/bn_mp_cnt_lsb.c
@@ -21,7 +21,7 @@ int mp_cnt_lsb(const mp_int *a)
    /* scan lower digits until non-zero */
    for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
    q = a->dp[x];
-   x *= DIGIT_BIT;
+   x *= MP_DIGIT_BIT;
 
    /* now scan this digit until a 1 is found */
    if ((q & 1u) == 0u) {
diff --git a/bn_mp_count_bits.c b/bn_mp_count_bits.c
index 44e7ffe..bba9a94 100644
--- a/bn_mp_count_bits.c
+++ b/bn_mp_count_bits.c
@@ -15,7 +15,7 @@ int mp_count_bits(const mp_int *a)
    }
 
    /* get number of digits and add that */
-   r = (a->used - 1) * DIGIT_BIT;
+   r = (a->used - 1) * MP_DIGIT_BIT;
 
    /* take the last digit and count the bits in it */
    q = a->dp[a->used - 1];
diff --git a/bn_mp_div.c b/bn_mp_div.c
index f36456d..53a342e 100644
--- a/bn_mp_div.c
+++ b/bn_mp_div.c
@@ -136,10 +136,10 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
    neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
    x.sign = y.sign = MP_ZPOS;
 
-   /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
-   norm = mp_count_bits(&y) % DIGIT_BIT;
-   if (norm < (DIGIT_BIT - 1)) {
-      norm = (DIGIT_BIT - 1) - norm;
+   /* normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT] */
+   norm = mp_count_bits(&y) % MP_DIGIT_BIT;
+   if (norm < (MP_DIGIT_BIT - 1)) {
+      norm = (MP_DIGIT_BIT - 1) - norm;
       if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) {
          goto LBL_Y;
       }
@@ -178,10 +178,10 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
       /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
        * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
       if (x.dp[i] == y.dp[t]) {
-         q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)DIGIT_BIT) - (mp_digit)1;
+         q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)MP_DIGIT_BIT) - (mp_digit)1;
       } else {
          mp_word tmp;
-         tmp = (mp_word)x.dp[i] << (mp_word)DIGIT_BIT;
+         tmp = (mp_word)x.dp[i] << (mp_word)MP_DIGIT_BIT;
          tmp |= (mp_word)x.dp[i - 1];
          tmp /= (mp_word)y.dp[t];
          if (tmp > (mp_word)MP_MASK) {
diff --git a/bn_mp_div_2.c b/bn_mp_div_2.c
index 645cd06..1cf7c8d 100644
--- a/bn_mp_div_2.c
+++ b/bn_mp_div_2.c
@@ -33,7 +33,7 @@ int mp_div_2(const mp_int *a, mp_int *b)
          rr = *tmpa & 1u;
 
          /* shift the current digit, add in carry and store */
-         *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
+         *tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
 
          /* forward carry to next iteration */
          r = rr;
diff --git a/bn_mp_div_2d.c b/bn_mp_div_2d.c
index b70ec13..e13c471 100644
--- a/bn_mp_div_2d.c
+++ b/bn_mp_div_2d.c
@@ -32,12 +32,12 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
    }
 
    /* shift by as many digits in the bit count */
-   if (b >= DIGIT_BIT) {
-      mp_rshd(c, b / DIGIT_BIT);
+   if (b >= MP_DIGIT_BIT) {
+      mp_rshd(c, b / MP_DIGIT_BIT);
    }
 
-   /* shift any bit count < DIGIT_BIT */
-   D = (mp_digit)(b % DIGIT_BIT);
+   /* shift any bit count < MP_DIGIT_BIT */
+   D = (mp_digit)(b % MP_DIGIT_BIT);
    if (D != 0u) {
       mp_digit *tmpc, mask, shift;
 
@@ -45,7 +45,7 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
       mask = ((mp_digit)1 << D) - 1uL;
 
       /* shift for lsb */
-      shift = (mp_digit)DIGIT_BIT - D;
+      shift = (mp_digit)MP_DIGIT_BIT - D;
 
       /* alias */
       tmpc = c->dp + (c->used - 1);
diff --git a/bn_mp_div_3.c b/bn_mp_div_3.c
index 3413a20..ccd8e85 100644
--- a/bn_mp_div_3.c
+++ b/bn_mp_div_3.c
@@ -11,8 +11,8 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
    mp_digit b;
    int      res, ix;
 
-   /* b = 2**DIGIT_BIT / 3 */
-   b = ((mp_word)1 << (mp_word)DIGIT_BIT) / (mp_word)3;
+   /* b = 2**MP_DIGIT_BIT / 3 */
+   b = ((mp_word)1 << (mp_word)MP_DIGIT_BIT) / (mp_word)3;
 
    if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
       return res;
@@ -22,11 +22,11 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
    q.sign = a->sign;
    w = 0;
    for (ix = a->used - 1; ix >= 0; ix--) {
-      w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
+      w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
 
       if (w >= 3u) {
          /* multiply w by [1/3] */
-         t = (w * (mp_word)b) >> (mp_word)DIGIT_BIT;
+         t = (w * (mp_word)b) >> (mp_word)MP_DIGIT_BIT;
 
          /* now subtract 3 * [w/3] from w, to get the remainder */
          w -= t+t+t;
diff --git a/bn_mp_div_d.c b/bn_mp_div_d.c
index e7e5870..c75e170 100644
--- a/bn_mp_div_d.c
+++ b/bn_mp_div_d.c
@@ -12,7 +12,7 @@ static int s_is_power_of_two(mp_digit b, int *p)
       return 0;
    }
 
-   for (x = 0; x < DIGIT_BIT; x++) {
+   for (x = 0; x < MP_DIGIT_BIT; x++) {
       if (b == ((mp_digit)1<<(mp_digit)x)) {
          *p = x;
          return 1;
@@ -72,7 +72,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
    q.sign = a->sign;
    w = 0;
    for (ix = a->used - 1; ix >= 0; ix--) {
-      w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
+      w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
 
       if (w >= b) {
          t = (mp_digit)(w / b);
diff --git a/bn_mp_dr_reduce.c b/bn_mp_dr_reduce.c
index a873a3c..83edbb6 100644
--- a/bn_mp_dr_reduce.c
+++ b/bn_mp_dr_reduce.c
@@ -51,7 +51,7 @@ top:
    for (i = 0; i < m; i++) {
       r         = ((mp_word)*tmpx2++ * (mp_word)k) + *tmpx1 + mu;
       *tmpx1++  = (mp_digit)(r & MP_MASK);
-      mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
+      mu        = (mp_digit)(r >> ((mp_word)MP_DIGIT_BIT));
    }
 
    /* set final carry */
diff --git a/bn_mp_dr_setup.c b/bn_mp_dr_setup.c
index 051cbe3..32d5f38 100644
--- a/bn_mp_dr_setup.c
+++ b/bn_mp_dr_setup.c
@@ -6,10 +6,10 @@
 /* determines the setup value */
 void mp_dr_setup(const mp_int *a, mp_digit *d)
 {
-   /* the casts are required if DIGIT_BIT is one less than
-    * the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
+   /* the casts are required if MP_DIGIT_BIT is one less than
+    * the number of bits in a mp_digit [e.g. MP_DIGIT_BIT==31]
     */
-   *d = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - (mp_word)a->dp[0]);
+   *d = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - (mp_word)a->dp[0]);
 }
 
 #endif
diff --git a/bn_mp_expt_d_ex.c b/bn_mp_expt_d_ex.c
index c7bfecf..9ce2d13 100644
--- a/bn_mp_expt_d_ex.c
+++ b/bn_mp_expt_d_ex.c
@@ -40,7 +40,7 @@ int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
          b >>= 1;
       }
    } else {
-      for (x = 0; x < (unsigned)DIGIT_BIT; x++) {
+      for (x = 0; x < (unsigned)MP_DIGIT_BIT; x++) {
          /* square */
          if ((res = mp_sqr(c, c)) != MP_OKAY) {
             mp_clear(&g);
@@ -48,7 +48,7 @@ int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
          }
 
          /* if the bit is set multiply */
-         if ((b & ((mp_digit)1 << (DIGIT_BIT - 1))) != 0u) {
+         if ((b & ((mp_digit)1 << (MP_DIGIT_BIT - 1))) != 0u) {
             if ((res = mp_mul(c, &g, c)) != MP_OKAY) {
                mp_clear(&g);
                return res;
diff --git a/bn_mp_get_bit.c b/bn_mp_get_bit.c
index 91e40f3..4c844cc 100644
--- a/bn_mp_get_bit.c
+++ b/bn_mp_get_bit.c
@@ -16,13 +16,13 @@ int mp_get_bit(const mp_int *a, int b)
       return MP_VAL;
    }
 
-   limb = b / DIGIT_BIT;
+   limb = b / MP_DIGIT_BIT;
 
    if (limb >= a->used) {
       return MP_NO;
    }
 
-   bit = (mp_digit)(1) << (b % DIGIT_BIT);
+   bit = (mp_digit)(1) << (b % MP_DIGIT_BIT);
 
    isset = a->dp[limb] & bit;
    return (isset != 0u) ? MP_YES : MP_NO;
diff --git a/bn_mp_get_double.c b/bn_mp_get_double.c
index 3a972bb..c9b1b19 100644
--- a/bn_mp_get_double.c
+++ b/bn_mp_get_double.c
@@ -7,7 +7,7 @@ double mp_get_double(const mp_int *a)
 {
    int i;
    double d = 0.0, fac = 1.0;
-   for (i = 0; i < DIGIT_BIT; ++i) {
+   for (i = 0; i < MP_DIGIT_BIT; ++i) {
       fac *= 2.0;
    }
    for (i = a->used; i --> 0;) {
diff --git a/bn_mp_get_long.c b/bn_mp_get_long.c
index 6ca1fbd..04bea5c 100644
--- a/bn_mp_get_long.c
+++ b/bn_mp_get_long.c
@@ -14,14 +14,14 @@ unsigned long mp_get_long(const mp_int *a)
    }
 
    /* get number of digits of the lsb we have to read */
-   i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+   i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
 
    /* get most significant digit of result */
    res = (unsigned long)a->dp[i];
 
-#if (ULONG_MAX != 0xFFFFFFFFUL) || (DIGIT_BIT < 32)
+#if (ULONG_MAX != 0xFFFFFFFFUL) || (MP_DIGIT_BIT < 32)
    while (--i >= 0) {
-      res = (res << DIGIT_BIT) | (unsigned long)a->dp[i];
+      res = (res << MP_DIGIT_BIT) | (unsigned long)a->dp[i];
    }
 #endif
    return res;
diff --git a/bn_mp_get_long_long.c b/bn_mp_get_long_long.c
index 3fa2021..88c5e0c 100644
--- a/bn_mp_get_long_long.c
+++ b/bn_mp_get_long_long.c
@@ -14,14 +14,14 @@ unsigned long long mp_get_long_long(const mp_int *a)
    }
 
    /* get number of digits of the lsb we have to read */
-   i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+   i = MP_MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT)) - 1;
 
    /* get most significant digit of result */
    res = (unsigned long long)a->dp[i];
 
-#if DIGIT_BIT < 64
+#if MP_DIGIT_BIT < 64
    while (--i >= 0) {
-      res = (res << DIGIT_BIT) | (unsigned long long)a->dp[i];
+      res = (res << MP_DIGIT_BIT) | (unsigned long long)a->dp[i];
    }
 #endif
    return res;
diff --git a/bn_mp_is_square.c b/bn_mp_is_square.c
index efc1157..637f155 100644
--- a/bn_mp_is_square.c
+++ b/bn_mp_is_square.c
@@ -44,7 +44,7 @@ int mp_is_square(const mp_int *arg, int *ret)
       return MP_OKAY;
    }
 
-   /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
+   /* First check mod 128 (suppose that MP_DIGIT_BIT is at least 7) */
    if (rem_128[127u & arg->dp[0]] == (char)1) {
       return MP_OKAY;
    }
diff --git a/bn_mp_mod_2d.c b/bn_mp_mod_2d.c
index 991e330..58f563a 100644
--- a/bn_mp_mod_2d.c
+++ b/bn_mp_mod_2d.c
@@ -15,7 +15,7 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c)
    }
 
    /* if the modulus is larger than the value than return */
-   if (b >= (a->used * DIGIT_BIT)) {
+   if (b >= (a->used * MP_DIGIT_BIT)) {
       res = mp_copy(a, c);
       return res;
    }
@@ -26,12 +26,12 @@ int mp_mod_2d(const mp_int *a, int b, mp_int *c)
    }
 
    /* zero digits above the last digit of the modulus */
-   for (x = (b / DIGIT_BIT) + (((b % DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) {
+   for (x = (b / MP_DIGIT_BIT) + (((b % MP_DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) {
       c->dp[x] = 0;
    }
    /* clear the digit that is not completely outside/inside the modulus */
-   c->dp[b / DIGIT_BIT] &=
-      ((mp_digit)1 << (mp_digit)(b % DIGIT_BIT)) - (mp_digit)1;
+   c->dp[b / MP_DIGIT_BIT] &=
+      ((mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT)) - (mp_digit)1;
    mp_clamp(c);
    return MP_OKAY;
 }
diff --git a/bn_mp_montgomery_calc_normalization.c b/bn_mp_montgomery_calc_normalization.c
index 77db883..1331db1 100644
--- a/bn_mp_montgomery_calc_normalization.c
+++ b/bn_mp_montgomery_calc_normalization.c
@@ -14,10 +14,10 @@ int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)
    int     x, bits, res;
 
    /* how many bits of last digit does b use */
-   bits = mp_count_bits(b) % DIGIT_BIT;
+   bits = mp_count_bits(b) % MP_DIGIT_BIT;
 
    if (b->used > 1) {
-      if ((res = mp_2expt(a, ((b->used - 1) * DIGIT_BIT) + bits - 1)) != MP_OKAY) {
+      if ((res = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) {
          return res;
       }
    } else {
@@ -27,7 +27,7 @@ int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b)
 
 
    /* now compute C = A * B mod b */
-   for (x = bits - 1; x < (int)DIGIT_BIT; x++) {
+   for (x = bits - 1; x < (int)MP_DIGIT_BIT; x++) {
       if ((res = mp_mul_2(a, a)) != MP_OKAY) {
          return res;
       }
diff --git a/bn_mp_montgomery_reduce.c b/bn_mp_montgomery_reduce.c
index a67cf29..bf24cbe 100644
--- a/bn_mp_montgomery_reduce.c
+++ b/bn_mp_montgomery_reduce.c
@@ -19,7 +19,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
    if ((digs < (int)MP_WARRAY) &&
        (x->used <= (int)MP_WARRAY) &&
        (n->used <
-        (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
+        (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
       return s_mp_montgomery_reduce_fast(x, n, rho);
    }
 
@@ -64,7 +64,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
                       (mp_word)u + (mp_word)*tmpx;
 
             /* get carry */
-            u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+            u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
 
             /* fix digit */
             *tmpx++ = (mp_digit)(r & (mp_word)MP_MASK);
@@ -75,7 +75,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
          /* propagate carries upwards as required*/
          while (u != 0u) {
             *tmpx   += u;
-            u        = *tmpx >> DIGIT_BIT;
+            u        = *tmpx >> MP_DIGIT_BIT;
             *tmpx++ &= MP_MASK;
          }
       }
diff --git a/bn_mp_montgomery_setup.c b/bn_mp_montgomery_setup.c
index 29f0fe3..ac5f532 100644
--- a/bn_mp_montgomery_setup.c
+++ b/bn_mp_montgomery_setup.c
@@ -35,7 +35,7 @@ int mp_montgomery_setup(const mp_int *n, mp_digit *rho)
 #endif
 
    /* rho = -1/m mod b */
-   *rho = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - x) & MP_MASK;
+   *rho = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - x) & MP_MASK;
 
    return MP_OKAY;
 }
diff --git a/bn_mp_mul.c b/bn_mp_mul.c
index d86a62b..5ea592b 100644
--- a/bn_mp_mul.c
+++ b/bn_mp_mul.c
@@ -67,7 +67,7 @@ GO_ON:
 #ifdef BN_S_MP_MUL_DIGS_FAST_C
          if ((digs < (int)MP_WARRAY) &&
              (MP_MIN(a->used, b->used) <=
-              (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
+              (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
             res = s_mp_mul_digs_fast(a, b, c, digs);
          } else
 #endif
diff --git a/bn_mp_mul_2.c b/bn_mp_mul_2.c
index 668043b..cd87d71 100644
--- a/bn_mp_mul_2.c
+++ b/bn_mp_mul_2.c
@@ -34,7 +34,7 @@ int mp_mul_2(const mp_int *a, mp_int *b)
          /* get what will be the *next* carry bit from the
           * MSB of the current digit
           */
-         rr = *tmpa >> (mp_digit)(DIGIT_BIT - 1);
+         rr = *tmpa >> (mp_digit)(MP_DIGIT_BIT - 1);
 
          /* now shift up this digit, add in the carry [from the previous] */
          *tmpb++ = ((*tmpa++ << 1uL) | r) & MP_MASK;
diff --git a/bn_mp_mul_2d.c b/bn_mp_mul_2d.c
index f6c6b57..f41618b 100644
--- a/bn_mp_mul_2d.c
+++ b/bn_mp_mul_2d.c
@@ -16,21 +16,21 @@ int mp_mul_2d(const mp_int *a, int b, mp_int *c)
       }
    }
 
-   if (c->alloc < (c->used + (b / DIGIT_BIT) + 1)) {
-      if ((res = mp_grow(c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) {
+   if (c->alloc < (c->used + (b / MP_DIGIT_BIT) + 1)) {
+      if ((res = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
          return res;
       }
    }
 
    /* shift by as many digits in the bit count */
-   if (b >= DIGIT_BIT) {
-      if ((res = mp_lshd(c, b / DIGIT_BIT)) != MP_OKAY) {
+   if (b >= MP_DIGIT_BIT) {
+      if ((res = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) {
          return res;
       }
    }
 
-   /* shift any bit count < DIGIT_BIT */
-   d = (mp_digit)(b % DIGIT_BIT);
+   /* shift any bit count < MP_DIGIT_BIT */
+   d = (mp_digit)(b % MP_DIGIT_BIT);
    if (d != 0u) {
       mp_digit *tmpc, shift, mask, r, rr;
       int x;
@@ -39,7 +39,7 @@ int mp_mul_2d(const mp_int *a, int b, mp_int *c)
       mask = ((mp_digit)1 << d) - (mp_digit)1;
 
       /* shift for msbs */
-      shift = (mp_digit)DIGIT_BIT - d;
+      shift = (mp_digit)MP_DIGIT_BIT - d;
 
       /* alias */
       tmpc = c->dp;
diff --git a/bn_mp_mul_d.c b/bn_mp_mul_d.c
index a7cd807..8419f72 100644
--- a/bn_mp_mul_d.c
+++ b/bn_mp_mul_d.c
@@ -41,7 +41,7 @@ int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
       *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
 
       /* send carry into next iteration */
-      u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+      u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
    }
 
    /* store final carry [if any] and increment ix offset  */
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index ff44419..b6f5927 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -296,10 +296,10 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
             fips_rand &= mask;
          }
 #endif
-         if (fips_rand > (unsigned int)(INT_MAX - DIGIT_BIT)) {
-            len = INT_MAX / DIGIT_BIT;
+         if (fips_rand > (unsigned int)(INT_MAX - MP_DIGIT_BIT)) {
+            len = INT_MAX / MP_DIGIT_BIT;
          } else {
-            len = (((int)fips_rand + DIGIT_BIT) / DIGIT_BIT);
+            len = (((int)fips_rand + MP_DIGIT_BIT) / MP_DIGIT_BIT);
          }
          /*  Unlikely. */
          if (len < 0) {
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index 857ae16..7d306fb 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -114,7 +114,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
                y = 1;
             }
          }
-      } while ((y == 1) && (step < (((mp_digit)1 << DIGIT_BIT) - kstep)));
+      } while ((y == 1) && (step < (((mp_digit)1 << MP_DIGIT_BIT) - kstep)));
 
       /* add the step */
       if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
@@ -122,7 +122,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
       }
 
       /* if didn't pass sieve and step == MP_MAX then skip test */
-      if ((y == 1) && (step >= (((mp_digit)1 << DIGIT_BIT) - kstep))) {
+      if ((y == 1) && (step >= (((mp_digit)1 << MP_DIGIT_BIT) - kstep))) {
          continue;
       }
 
diff --git a/bn_mp_reduce.c b/bn_mp_reduce.c
index 127fa62..e6a8bd2 100644
--- a/bn_mp_reduce.c
+++ b/bn_mp_reduce.c
@@ -21,7 +21,7 @@ int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
    mp_rshd(&q, um - 1);
 
    /* according to HAC this optimization is ok */
-   if ((mp_digit)um > ((mp_digit)1 << (DIGIT_BIT - 1))) {
+   if ((mp_digit)um > ((mp_digit)1 << (MP_DIGIT_BIT - 1))) {
       if ((res = mp_mul(&q, mu, &q)) != MP_OKAY) {
          goto CLEANUP;
       }
@@ -46,7 +46,7 @@ int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu)
    mp_rshd(&q, um + 1);
 
    /* x = x mod b**(k+1), quick (no division) */
-   if ((res = mp_mod_2d(x, DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
+   if ((res = mp_mod_2d(x, MP_DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
       goto CLEANUP;
    }
 
diff --git a/bn_mp_reduce_is_2k.c b/bn_mp_reduce_is_2k.c
index 42db597..aea0840 100644
--- a/bn_mp_reduce_is_2k.c
+++ b/bn_mp_reduce_is_2k.c
@@ -19,7 +19,7 @@ int mp_reduce_is_2k(const mp_int *a)
       iw = 1;
 
       /* Test every bit from the second digit up, must be 1 */
-      for (ix = DIGIT_BIT; ix < iy; ix++) {
+      for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
          if ((a->dp[iw] & iz) == 0u) {
             return MP_NO;
          }
diff --git a/bn_mp_reduce_setup.c b/bn_mp_reduce_setup.c
index a62f1bf..7cd7909 100644
--- a/bn_mp_reduce_setup.c
+++ b/bn_mp_reduce_setup.c
@@ -10,7 +10,7 @@ int mp_reduce_setup(mp_int *a, const mp_int *b)
 {
    int     res;
 
-   if ((res = mp_2expt(a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {
+   if ((res = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) {
       return res;
    }
    return mp_div(a, b, a, NULL);
diff --git a/bn_mp_sqr.c b/bn_mp_sqr.c
index 6daee58..531939f 100644
--- a/bn_mp_sqr.c
+++ b/bn_mp_sqr.c
@@ -25,7 +25,7 @@ int mp_sqr(const mp_int *a, mp_int *b)
          /* can we use the fast comba multiplier? */
          if ((((a->used * 2) + 1) < (int)MP_WARRAY) &&
              (a->used <
-              (int)(1u << (((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT)) - 1u)))) {
+              (int)(1u << (((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT)) - 1u)))) {
             res = s_mp_sqr_fast(a, b);
          } else
 #endif
diff --git a/bn_s_mp_add.c b/bn_s_mp_add.c
index a369cc2..77b851e 100644
--- a/bn_s_mp_add.c
+++ b/bn_s_mp_add.c
@@ -55,7 +55,7 @@ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
          *tmpc = *tmpa++ + *tmpb++ + u;
 
          /* U = carry bit of T[i] */
-         u = *tmpc >> (mp_digit)DIGIT_BIT;
+         u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
 
          /* take away carry bit from T[i] */
          *tmpc++ &= MP_MASK;
@@ -70,7 +70,7 @@ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
             *tmpc = x->dp[i] + u;
 
             /* U = carry bit of T[i] */
-            u = *tmpc >> (mp_digit)DIGIT_BIT;
+            u = *tmpc >> (mp_digit)MP_DIGIT_BIT;
 
             /* take away carry bit from T[i] */
             *tmpc++ &= MP_MASK;
diff --git a/bn_s_mp_exptmod.c b/bn_s_mp_exptmod.c
index c8e5480..20572d4 100644
--- a/bn_s_mp_exptmod.c
+++ b/bn_s_mp_exptmod.c
@@ -141,11 +141,11 @@ int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, i
          }
          /* read next digit and reset the bitcnt */
          buf    = X->dp[digidx--];
-         bitcnt = (int)DIGIT_BIT;
+         bitcnt = (int)MP_DIGIT_BIT;
       }
 
       /* grab the next msb from the exponent */
-      y     = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1;
+      y     = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1;
       buf <<= (mp_digit)1;
 
       /* if the bit is zero and mode == 0 then we ignore it
diff --git a/bn_s_mp_exptmod_fast.c b/bn_s_mp_exptmod_fast.c
index 277954b..af6ae57 100644
--- a/bn_s_mp_exptmod_fast.c
+++ b/bn_s_mp_exptmod_fast.c
@@ -85,7 +85,7 @@ int s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int 
       /* automatically pick the comba one if available (saves quite a few calls/ifs) */
 #ifdef BN_S_MP_MONTGOMERY_REDUCE_FAST_C
       if ((((P->used * 2) + 1) < (int)MP_WARRAY) &&
-          (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
+          (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * MP_DIGIT_BIT))))) {
          redux = s_mp_montgomery_reduce_fast;
       } else
 #endif
@@ -195,11 +195,11 @@ int s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int 
          }
          /* read next digit and reset bitcnt */
          buf    = X->dp[digidx--];
-         bitcnt = (int)DIGIT_BIT;
+         bitcnt = (int)MP_DIGIT_BIT;
       }
 
       /* grab the next msb from the exponent */
-      y     = (mp_digit)(buf >> (DIGIT_BIT - 1)) & 1;
+      y     = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1;
       buf <<= (mp_digit)1;
 
       /* if the bit is zero and mode == 0 then we ignore it
diff --git a/bn_s_mp_karatsuba_mul.c b/bn_s_mp_karatsuba_mul.c
index 3a3e5df..15d3b11 100644
--- a/bn_s_mp_karatsuba_mul.c
+++ b/bn_s_mp_karatsuba_mul.c
@@ -6,7 +6,7 @@
 /* c = |a| * |b| using Karatsuba Multiplication using
  * three half size multiplications
  *
- * Let B represent the radix [e.g. 2**DIGIT_BIT] and
+ * Let B represent the radix [e.g. 2**MP_DIGIT_BIT] and
  * let n represent half of the number of digits in
  * the min(a,b)
  *
diff --git a/bn_s_mp_montgomery_reduce_fast.c b/bn_s_mp_montgomery_reduce_fast.c
index 0402701..a9a9a60 100644
--- a/bn_s_mp_montgomery_reduce_fast.c
+++ b/bn_s_mp_montgomery_reduce_fast.c
@@ -99,7 +99,7 @@ int s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho)
       }
 
       /* now fix carry for next digit, W[ix+1] */
-      W[ix + 1] += W[ix] >> (mp_word)DIGIT_BIT;
+      W[ix + 1] += W[ix] >> (mp_word)MP_DIGIT_BIT;
    }
 
    /* now we have to propagate the carries and
@@ -119,7 +119,7 @@ int s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho)
       _W = W + ++ix;
 
       for (; ix <= ((n->used * 2) + 1); ix++) {
-         *_W++ += *_W1++ >> (mp_word)DIGIT_BIT;
+         *_W++ += *_W1++ >> (mp_word)MP_DIGIT_BIT;
       }
 
       /* copy out, A = A/b**n
diff --git a/bn_s_mp_mul_digs.c b/bn_s_mp_mul_digs.c
index 8ec5a88..9e925c7 100644
--- a/bn_s_mp_mul_digs.c
+++ b/bn_s_mp_mul_digs.c
@@ -18,7 +18,7 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
    /* can we use the fast multiplier? */
    if ((digs < (int)MP_WARRAY) &&
        (MP_MIN(a->used, b->used) <
-        (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
+        (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
       return s_mp_mul_digs_fast(a, b, c, digs);
    }
 
@@ -57,7 +57,7 @@ int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
 
          /* get the carry word from the result */
-         u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
       }
       /* set carry if it is placed below digs */
       if ((ix + iy) < digs) {
diff --git a/bn_s_mp_mul_digs_fast.c b/bn_s_mp_mul_digs_fast.c
index c4c0310..e9af5ed 100644
--- a/bn_s_mp_mul_digs_fast.c
+++ b/bn_s_mp_mul_digs_fast.c
@@ -65,7 +65,7 @@ int s_mp_mul_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs)
       W[ix] = (mp_digit)_W & MP_MASK;
 
       /* make next carry */
-      _W = _W >> (mp_word)DIGIT_BIT;
+      _W = _W >> (mp_word)MP_DIGIT_BIT;
    }
 
    /* setup dest */
diff --git a/bn_s_mp_mul_high_digs.c b/bn_s_mp_mul_high_digs.c
index 7a2155f..416ac8c 100644
--- a/bn_s_mp_mul_high_digs.c
+++ b/bn_s_mp_mul_high_digs.c
@@ -17,7 +17,7 @@ int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
    /* can we use the fast multiplier? */
 #ifdef BN_S_MP_MUL_HIGH_DIGS_FAST_C
    if (((a->used + b->used + 1) < (int)MP_WARRAY)
-       && (MP_MIN(a->used, b->used) < (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
+       && (MP_MIN(a->used, b->used) < (int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)MP_DIGIT_BIT))))) {
       return s_mp_mul_high_digs_fast(a, b, c, digs);
    }
 #endif
@@ -52,7 +52,7 @@ int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
 
          /* carry the carry */
-         u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
       }
       *tmpt = u;
    }
diff --git a/bn_s_mp_mul_high_digs_fast.c b/bn_s_mp_mul_high_digs_fast.c
index c42d6d0..fe4bd8e 100644
--- a/bn_s_mp_mul_high_digs_fast.c
+++ b/bn_s_mp_mul_high_digs_fast.c
@@ -55,7 +55,7 @@ int s_mp_mul_high_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int dig
       W[ix] = (mp_digit)_W & MP_MASK;
 
       /* make next carry */
-      _W = _W >> (mp_word)DIGIT_BIT;
+      _W = _W >> (mp_word)MP_DIGIT_BIT;
    }
 
    /* setup dest */
diff --git a/bn_s_mp_sqr.c b/bn_s_mp_sqr.c
index 05ce968..b6f0ea0 100644
--- a/bn_s_mp_sqr.c
+++ b/bn_s_mp_sqr.c
@@ -29,7 +29,7 @@ int s_mp_sqr(const mp_int *a, mp_int *b)
       t.dp[ix+ix] = (mp_digit)(r & (mp_word)MP_MASK);
 
       /* get the carry */
-      u           = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+      u           = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
 
       /* left hand side of A[ix] * A[iy] */
       tmpx        = a->dp[ix];
@@ -50,13 +50,13 @@ int s_mp_sqr(const mp_int *a, mp_int *b)
          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
 
          /* get carry */
-         u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
       }
       /* propagate upwards */
       while (u != 0uL) {
          r       = (mp_word)*tmpt + (mp_word)u;
          *tmpt++ = (mp_digit)(r & (mp_word)MP_MASK);
-         u       = (mp_digit)(r >> (mp_word)DIGIT_BIT);
+         u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
       }
    }
 
diff --git a/bn_s_mp_sqr_fast.c b/bn_s_mp_sqr_fast.c
index cc77200..42548c0 100644
--- a/bn_s_mp_sqr_fast.c
+++ b/bn_s_mp_sqr_fast.c
@@ -73,7 +73,7 @@ int s_mp_sqr_fast(const mp_int *a, mp_int *b)
       W[ix] = (mp_digit)_W & MP_MASK;
 
       /* make next carry */
-      W1 = _W >> (mp_word)DIGIT_BIT;
+      W1 = _W >> (mp_word)MP_DIGIT_BIT;
    }
 
    /* setup dest */
diff --git a/bn_s_mp_toom_mul.c b/bn_s_mp_toom_mul.c
index a60d16a..edb7b59 100644
--- a/bn_s_mp_toom_mul.c
+++ b/bn_s_mp_toom_mul.c
@@ -26,7 +26,7 @@ int s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
    B = MP_MIN(a->used, b->used) / 3;
 
    /* a = a2 * B**2 + a1 * B + a0 */
-   if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
+   if ((res = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) {
       goto LBL_ERR;
    }
 
@@ -34,7 +34,7 @@ int s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
       goto LBL_ERR;
    }
    mp_rshd(&a1, B);
-   if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+   if ((res = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) {
       goto LBL_ERR;
    }
 
@@ -44,7 +44,7 @@ int s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
    mp_rshd(&a2, B*2);
 
    /* b = b2 * B**2 + b1 * B + b0 */
-   if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) {
+   if ((res = mp_mod_2d(b, MP_DIGIT_BIT * B, &b0)) != MP_OKAY) {
       goto LBL_ERR;
    }
 
@@ -52,7 +52,7 @@ int s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
       goto LBL_ERR;
    }
    mp_rshd(&b1, B);
-   (void)mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
+   (void)mp_mod_2d(&b1, MP_DIGIT_BIT * B, &b1);
 
    if ((res = mp_copy(b, &b2)) != MP_OKAY) {
       goto LBL_ERR;
diff --git a/bn_s_mp_toom_sqr.c b/bn_s_mp_toom_sqr.c
index d26b59c..72cbea8 100644
--- a/bn_s_mp_toom_sqr.c
+++ b/bn_s_mp_toom_sqr.c
@@ -18,7 +18,7 @@ int s_mp_toom_sqr(const mp_int *a, mp_int *b)
    B = a->used / 3;
 
    /* a = a2 * B**2 + a1 * B + a0 */
-   if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
+   if ((res = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) {
       goto LBL_ERR;
    }
 
@@ -26,7 +26,7 @@ int s_mp_toom_sqr(const mp_int *a, mp_int *b)
       goto LBL_ERR;
    }
    mp_rshd(&a1, B);
-   if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+   if ((res = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) {
       goto LBL_ERR;
    }
 
diff --git a/demo/main.c b/demo/main.c
index f1fc993..883f54d 100644
--- a/demo/main.c
+++ b/demo/main.c
@@ -42,7 +42,7 @@ int main(void)
 #endif
    printf("Size of mp_digit: %u\n", (unsigned int)sizeof(mp_digit));
    printf("Size of mp_word: %u\n", (unsigned int)sizeof(mp_word));
-   printf("DIGIT_BIT: %d\n", DIGIT_BIT);
+   printf("MP_DIGIT_BIT: %d\n", MP_DIGIT_BIT);
    printf("MP_PREC: %d\n", MP_PREC);
 
    if (LTM_DEMO_TEST_VS_MTEST) {
diff --git a/demo/test.c b/demo/test.c
index 208ab7f..9c71d5b 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -1056,7 +1056,7 @@ static int test_mp_reduce_2k(void)
             printf(".");
             fflush(stdout);
          }
-         mp_rand(&b, (cnt / DIGIT_BIT + 1) * 2);
+         mp_rand(&b, (cnt / MP_DIGIT_BIT + 1) * 2);
          mp_copy(&c, &b);
          mp_mod(&c, &a, &c);
          mp_reduce_2k(&b, &a, 2uL);
diff --git a/demo/timing.c b/demo/timing.c
index 8ebb4a7..5db905b 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -177,7 +177,7 @@ int main(void)
       } while (++rr < 100000u);
       printf("Adding\t\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
              mp_count_bits(&a), CLK_PER_SEC / tt, tt);
-      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * DIGIT_BIT, tt);
+      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * MP_DIGIT_BIT, tt);
       FFLUSH(log);
    }
    FCLOSE(log);
@@ -199,7 +199,7 @@ int main(void)
 
       printf("Subtracting\t\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
              mp_count_bits(&a), CLK_PER_SEC / tt, tt);
-      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * DIGIT_BIT, tt);
+      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * MP_DIGIT_BIT, tt);
       FFLUSH(log);
    }
    FCLOSE(log);
@@ -219,7 +219,7 @@ int main(void)
       TOOM_SQR_CUTOFF = (ix == 2) ? old_toom_s : 9999;
 
       log = FOPEN((ix == 0) ? "logs/mult.log" : (ix == 1) ? "logs/mult_kara.log" : "logs/mult_toom.log", "w");
-      for (cnt = 4; cnt <= (10240 / DIGIT_BIT); cnt += 2) {
+      for (cnt = 4; cnt <= (10240 / MP_DIGIT_BIT); cnt += 2) {
          SLEEP;
          mp_rand(&a, cnt);
          mp_rand(&b, cnt);
@@ -240,7 +240,7 @@ int main(void)
       FCLOSE(log);
 
       log = FOPEN((ix == 0) ? "logs/sqr.log" : (ix == 1) ? "logs/sqr_kara.log" : "logs/sqr_toom.log", "w");
-      for (cnt = 4; cnt <= (10240 / DIGIT_BIT); cnt += 2) {
+      for (cnt = 4; cnt <= (10240 / MP_DIGIT_BIT); cnt += 2) {
          SLEEP;
          mp_rand(&a, cnt);
          rr = 0u;
@@ -366,7 +366,7 @@ int main(void)
       }
       printf("Inverting mod\t%4d-bit => %9" PRIu64 "/sec, %9" PRIu64 " cycles\n",
              mp_count_bits(&a), CLK_PER_SEC / tt, tt);
-      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * DIGIT_BIT, tt);
+      FPRINTF(log, "%6d %9" PRIu64 "\n", cnt * MP_DIGIT_BIT, tt);
    }
    FCLOSE(log);
 
diff --git a/etc/drprime.c b/etc/drprime.c
index aa24778..1714e68 100644
--- a/etc/drprime.c
+++ b/etc/drprime.c
@@ -1,7 +1,7 @@
 /* Makes safe primes of a DR nature */
 #include <tommath.h>
 
-static int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
+static int sizes[] = { 1+256/MP_DIGIT_BIT, 1+512/MP_DIGIT_BIT, 1+768/MP_DIGIT_BIT, 1+1024/MP_DIGIT_BIT, 1+2048/MP_DIGIT_BIT, 1+4096/MP_DIGIT_BIT };
 
 int main(void)
 {
@@ -17,7 +17,7 @@ int main(void)
    if (out != NULL) {
       for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
 top:
-         printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
+         printf("Seeking a %d-bit safe prime\n", sizes[x] * MP_DIGIT_BIT);
          mp_grow(&a, sizes[x]);
          mp_zero(&a);
          for (y = 1; y < sizes[x]; y++) {
diff --git a/etc/pprime.c b/etc/pprime.c
index 2c851c3..68f882a 100644
--- a/etc/pprime.c
+++ b/etc/pprime.c
@@ -185,7 +185,7 @@ static int pprime(int k, int li, mp_int *p, mp_int *q)
    static const mp_digit bases[] = { 2, 3, 5, 7, 11, 13, 17, 19 };
 
    /* single digit ? */
-   if (k <= (int) DIGIT_BIT) {
+   if (k <= (int) MP_DIGIT_BIT) {
       mp_set(p, prime_digit());
       return MP_OKAY;
    }
diff --git a/tommath.h b/tommath.h
index c7276b5..7943084 100644
--- a/tommath.h
+++ b/tommath.h
@@ -43,8 +43,8 @@ extern "C" {
 
 /* some default configurations.
  *
- * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
- * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
+ * A "mp_digit" must be able to hold MP_DIGIT_BIT + 1 bits
+ * A "mp_word" must be able to hold 2*MP_DIGIT_BIT + 1 bits
  *
  * At the very least a mp_digit must be able to hold 7 bits
  * [any size beyond that is ok provided it doesn't overflow the data type]
@@ -53,21 +53,21 @@ extern "C" {
 typedef uint8_t              mp_digit;
 typedef uint16_t             mp_word;
 #   define MP_SIZEOF_MP_DIGIT 1
-#   ifdef DIGIT_BIT
-#      error You must not define DIGIT_BIT when using MP_8BIT
+#   ifdef MP_DIGIT_BIT
+#      error You must not define MP_DIGIT_BIT when using MP_8BIT
 #   endif
 #elif defined(MP_16BIT)
 typedef uint16_t             mp_digit;
 typedef uint32_t             mp_word;
 #   define MP_SIZEOF_MP_DIGIT 2
-#   ifdef DIGIT_BIT
-#      error You must not define DIGIT_BIT when using MP_16BIT
+#   ifdef MP_DIGIT_BIT
+#      error You must not define MP_DIGIT_BIT when using MP_16BIT
 #   endif
 #elif defined(MP_64BIT)
 /* for GCC only on supported platforms */
 typedef uint64_t mp_digit;
 typedef unsigned long        mp_word __attribute__((mode(TI)));
-#   define DIGIT_BIT 60
+#   define MP_DIGIT_BIT 60
 #else
 /* this is the default case, 28-bit digits */
 
@@ -77,21 +77,20 @@ typedef uint64_t             mp_word;
 
 #   ifdef MP_31BIT
 /* this is an extension that uses 31-bit digits */
-#      define DIGIT_BIT 31
+#      define MP_DIGIT_BIT 31
 #   else
 /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
-#      define DIGIT_BIT 28
+#      define MP_DIGIT_BIT 28
 #      define MP_28BIT
 #   endif
 #endif
 
 /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
-#ifndef DIGIT_BIT
-#   define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1))  /* bits per digit */
+#ifndef MP_DIGIT_BIT
+#   define MP_DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1))  /* bits per digit */
 #endif
 
-#define MP_DIGIT_BIT     DIGIT_BIT
-#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
+#define MP_MASK          ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
 #define MP_DIGIT_MAX     MP_MASK
 
 /* equalities */
@@ -137,7 +136,7 @@ extern int KARATSUBA_MUL_CUTOFF,
 #endif
 
 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
-#define MP_WARRAY               (1u << (((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT)) + 1))
+#define MP_WARRAY               (1u << (((CHAR_BIT * sizeof(mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
 
 /* the infamous mp_int structure */
 typedef struct  {
@@ -160,6 +159,7 @@ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
 #  define MP_DEPRECATED_PRAGMA(s)
 #endif
 
+#define DIGIT_BIT   (MP_DEPRECATED_PRAGMA("DIGIT_BIT macro is deprecated, MP_DIGIT_BIT instead") MP_DIGIT_BIT)
 #define USED(m)     (MP_DEPRECATED_PRAGMA("USED macro is deprecated, use z->used instead") (m)->used)
 #define DIGIT(m, k) (MP_DEPRECATED_PRAGMA("DIGIT macro is deprecated, use z->dp instead") (m)->dp[(k)])
 #define SIGN(m)     (MP_DEPRECATED_PRAGMA("SIGN macro is deprecated, use z->sign instead") (m)->sign)
diff --git a/tommath_private.h b/tommath_private.h
index d3dc496..03f93f0 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -68,14 +68,14 @@ extern const size_t mp_s_rmap_reverse_sz;
 int func_name (mp_int * a, type b)                       \
 {                                                        \
    int x = 0;                                            \
-   int new_size = (((CHAR_BIT * sizeof(type)) + DIGIT_BIT) - 1) / DIGIT_BIT; \
+   int new_size = (((CHAR_BIT * sizeof(type)) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT; \
    int res = mp_grow(a, new_size);                       \
    if (res == MP_OKAY) {                                 \
      mp_zero(a);                                         \
      while (b != 0u) {                                   \
         a->dp[x++] = ((mp_digit)b & MP_MASK);            \
-        if ((CHAR_BIT * sizeof (b)) <= DIGIT_BIT) { break; } \
-        b >>= (((CHAR_BIT * sizeof (b)) <= DIGIT_BIT) ? 0 : DIGIT_BIT); \
+        if ((CHAR_BIT * sizeof (b)) <= MP_DIGIT_BIT) { break; } \
+        b >>= (((CHAR_BIT * sizeof (b)) <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT); \
      }                                                   \
      a->used = x;                                        \
    }                                                     \