summaryrefslogtreecommitdiff
path: root/lib/freebl/mpi
diff options
context:
space:
mode:
authorMartin Thomson <martin.thomson@gmail.com>2015-08-12 09:44:25 -0700
committerMartin Thomson <martin.thomson@gmail.com>2015-08-12 09:44:25 -0700
commit225703849bf43ff466e4dcfd3b68c30486e8ad12 (patch)
treea6970da1dad182eb7e0d6a346cec7bb89205a789 /lib/freebl/mpi
parentdf18e4c7e5e9ad31fab45575896fba7d2bc24250 (diff)
downloadnss-hg-225703849bf43ff466e4dcfd3b68c30486e8ad12.tar.gz
Backed out changeset 4355f55afeb2 (Bug 1158489)
Diffstat (limited to 'lib/freebl/mpi')
-rw-r--r--lib/freebl/mpi/mpcpucache.c29
-rw-r--r--lib/freebl/mpi/mpi-priv.h4
-rw-r--r--lib/freebl/mpi/mpi.c34
-rw-r--r--lib/freebl/mpi/mpi.h2
-rw-r--r--lib/freebl/mpi/mplogic.c4
-rw-r--r--lib/freebl/mpi/mplogic.h2
-rw-r--r--lib/freebl/mpi/mpmontg.c2
-rw-r--r--lib/freebl/mpi/mpprime.c2
8 files changed, 47 insertions, 32 deletions
diff --git a/lib/freebl/mpi/mpcpucache.c b/lib/freebl/mpi/mpcpucache.c
index 925006110..9a4a9d30c 100644
--- a/lib/freebl/mpi/mpcpucache.c
+++ b/lib/freebl/mpi/mpcpucache.c
@@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mpi.h"
-#include "prtypes.h"
/*
* This file implements a single function: s_mpi_getProcessorLineSize();
@@ -620,17 +619,35 @@ unsigned long
s_mpi_is_sse2()
{
unsigned long eax, ebx, ecx, edx;
+ int manufacturer = MAN_UNKNOWN;
+ int i;
+ char string[13];
if (is386() || is486()) {
return 0;
}
freebl_cpuid(0, &eax, &ebx, &ecx, &edx);
+ /* string holds the CPU's manufacturer ID string - a twelve
+ * character ASCII string stored in ebx, edx, ecx, and
+ * the 32-bit extended feature flags are in edx, ecx.
+ */
+ *(int *)string = ebx;
+ *(int *)&string[4] = (int)edx;
+ *(int *)&string[8] = (int)ecx;
+ string[12] = 0;
/* has no SSE2 extensions */
if (eax == 0) {
return 0;
}
+ for (i=0; i < n_manufacturers; i++) {
+ if ( strcmp(manMap[i],string) == 0) {
+ manufacturer = i;
+ break;
+ }
+ }
+
freebl_cpuid(1,&eax,&ebx,&ecx,&edx);
return (edx & SSE2_FLAG) == SSE2_FLAG;
}
@@ -640,12 +657,11 @@ unsigned long
s_mpi_getProcessorLineSize()
{
unsigned long eax, ebx, ecx, edx;
- PRUint32 cpuid[3];
unsigned long cpuidLevel;
unsigned long cacheLineSize = 0;
int manufacturer = MAN_UNKNOWN;
int i;
- char string[13];
+ char string[65];
#if !defined(AMD_64)
if (is386()) {
@@ -662,10 +678,9 @@ s_mpi_getProcessorLineSize()
* character ASCII string stored in ebx, edx, ecx, and
* the 32-bit extended feature flags are in edx, ecx.
*/
- cpuid[0] = ebx;
- cpuid[1] = ecx;
- cpuid[2] = edx;
- memcpy(string, cpuid, sizeof(cpuid));
+ *(int *)string = ebx;
+ *(int *)&string[4] = (int)edx;
+ *(int *)&string[8] = (int)ecx;
string[12] = 0;
manufacturer = MAN_UNKNOWN;
diff --git a/lib/freebl/mpi/mpi-priv.h b/lib/freebl/mpi/mpi-priv.h
index 7a0725f46..e81d0fe0e 100644
--- a/lib/freebl/mpi/mpi-priv.h
+++ b/lib/freebl/mpi/mpi-priv.h
@@ -254,10 +254,8 @@ mp_err MPI_ASM_DECL s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo,
mp_digit divisor, mp_digit *quot, mp_digit *rem);
/* c += a * b * (MP_RADIX ** offset); */
-/* Callers of this macro should be aware that the return type might vary;
- * it should be treated as a void function. */
#define s_mp_mul_d_add_offset(a, b, c, off) \
- s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off)
+(s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off), MP_OKAY)
typedef struct {
mp_int N; /* modulus N */
diff --git a/lib/freebl/mpi/mpi.c b/lib/freebl/mpi/mpi.c
index 43ce83ae6..2a3719b88 100644
--- a/lib/freebl/mpi/mpi.c
+++ b/lib/freebl/mpi/mpi.c
@@ -1095,7 +1095,7 @@ mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c)
mp_int s, x;
mp_err res;
mp_digit d;
- unsigned int dig, bit;
+ int dig, bit;
ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
@@ -1470,7 +1470,7 @@ mp_err s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c
mp_int s, x, mu;
mp_err res;
mp_digit d;
- unsigned int dig, bit;
+ int dig, bit;
ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
@@ -2004,7 +2004,7 @@ mp_size mp_trailing_zeros(const mp_int *mp)
{
mp_digit d;
mp_size n = 0;
- unsigned int ix;
+ int ix;
if (!mp || !MP_DIGITS(mp) || !mp_cmp_z(mp))
return n;
@@ -2916,7 +2916,8 @@ void s_mp_exch(mp_int *a, mp_int *b)
mp_err s_mp_lshd(mp_int *mp, mp_size p)
{
mp_err res;
- unsigned int ix;
+ mp_size pos;
+ int ix;
if(p == 0)
return MP_OKAY;
@@ -2927,13 +2928,14 @@ mp_err s_mp_lshd(mp_int *mp, mp_size p)
if((res = s_mp_pad(mp, USED(mp) + p)) != MP_OKAY)
return res;
+ pos = USED(mp) - 1;
+
/* Shift all the significant figures over as needed */
- for (ix = USED(mp) - p; ix-- > 0;) {
+ for(ix = pos - p; ix >= 0; ix--)
DIGIT(mp, ix + p) = DIGIT(mp, ix);
- }
/* Fill the bottom digits with zeroes */
- for(ix = 0; (mp_size)ix < p; ix++)
+ for(ix = 0; ix < p; ix++)
DIGIT(mp, ix) = 0;
return MP_OKAY;
@@ -3044,7 +3046,7 @@ void s_mp_div_2(mp_int *mp)
mp_err s_mp_mul_2(mp_int *mp)
{
mp_digit *pd;
- unsigned int ix, used;
+ int ix, used;
mp_digit kin = 0;
/* Shift digits leftward by 1 bit */
@@ -4670,10 +4672,10 @@ mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len)
/* }}} */
/* {{{ mp_unsigned_octet_size(mp) */
-unsigned int
+int
mp_unsigned_octet_size(const mp_int *mp)
{
- unsigned int bytes;
+ int bytes;
int ix;
mp_digit d = 0;
@@ -4710,12 +4712,12 @@ mp_err
mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen)
{
int ix, pos = 0;
- unsigned int bytes;
+ int bytes;
ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
bytes = mp_unsigned_octet_size(mp);
- ARGCHK(bytes <= maxlen, MP_BADARG);
+ ARGCHK(bytes >= 0 && bytes <= maxlen, MP_BADARG);
/* Iterate over each digit... */
for(ix = USED(mp) - 1; ix >= 0; ix--) {
@@ -4742,12 +4744,12 @@ mp_err
mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen)
{
int ix, pos = 0;
- unsigned int bytes;
+ int bytes;
ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
bytes = mp_unsigned_octet_size(mp);
- ARGCHK(bytes <= maxlen, MP_BADARG);
+ ARGCHK(bytes >= 0 && bytes <= maxlen, MP_BADARG);
/* Iterate over each digit... */
for(ix = USED(mp) - 1; ix >= 0; ix--) {
@@ -4782,12 +4784,12 @@ mp_err
mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size length)
{
int ix, pos = 0;
- unsigned int bytes;
+ int bytes;
ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG);
bytes = mp_unsigned_octet_size(mp);
- ARGCHK(bytes <= length, MP_BADARG);
+ ARGCHK(bytes >= 0 && bytes <= length, MP_BADARG);
/* place any needed leading zeros */
for (;length > bytes; --length) {
diff --git a/lib/freebl/mpi/mpi.h b/lib/freebl/mpi/mpi.h
index b1b45d257..a556c17e9 100644
--- a/lib/freebl/mpi/mpi.h
+++ b/lib/freebl/mpi/mpi.h
@@ -258,7 +258,7 @@ const char *mp_strerror(mp_err ec);
/* Octet string conversion functions */
mp_err mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len);
-unsigned int mp_unsigned_octet_size(const mp_int *mp);
+int mp_unsigned_octet_size(const mp_int *mp);
mp_err mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen);
mp_err mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen);
mp_err mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size len);
diff --git a/lib/freebl/mpi/mplogic.c b/lib/freebl/mpi/mplogic.c
index df0aad0e1..dbec7acfc 100644
--- a/lib/freebl/mpi/mplogic.c
+++ b/lib/freebl/mpi/mplogic.c
@@ -403,9 +403,9 @@ mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits)
returns number of significnant bits in abs(a).
returns 1 if value is zero.
*/
-mp_size mpl_significant_bits(const mp_int *a)
+mp_err mpl_significant_bits(const mp_int *a)
{
- mp_size bits = 0;
+ mp_err bits = 0;
int ix;
ARGCHK(a != NULL, MP_BADARG);
diff --git a/lib/freebl/mpi/mplogic.h b/lib/freebl/mpi/mplogic.h
index e05374a82..f45fe3665 100644
--- a/lib/freebl/mpi/mplogic.h
+++ b/lib/freebl/mpi/mplogic.h
@@ -47,6 +47,6 @@ mp_err mpl_parity(mp_int *a); /* determine parity */
mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value);
mp_err mpl_get_bit(const mp_int *a, mp_size bitNum);
mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits);
-mp_size mpl_significant_bits(const mp_int *a);
+mp_err mpl_significant_bits(const mp_int *a);
#endif /* end _H_MPLOGIC_ */
diff --git a/lib/freebl/mpi/mpmontg.c b/lib/freebl/mpi/mpmontg.c
index 9667755d0..d619360aa 100644
--- a/lib/freebl/mpi/mpmontg.c
+++ b/lib/freebl/mpi/mpmontg.c
@@ -47,7 +47,7 @@ mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm)
for (i = 0; i < MP_USED(&mmm->N); ++i ) {
mp_digit m_i = MP_DIGIT(T, i) * mmm->n0prime;
/* T += N * m_i * (MP_RADIX ** i); */
- s_mp_mul_d_add_offset(&mmm->N, m_i, T, i);
+ MP_CHECKOK( s_mp_mul_d_add_offset(&mmm->N, m_i, T, i) );
}
s_mp_clamp(T);
diff --git a/lib/freebl/mpi/mpprime.c b/lib/freebl/mpi/mpprime.c
index 9b97fb206..f0baf9d2a 100644
--- a/lib/freebl/mpi/mpprime.c
+++ b/lib/freebl/mpi/mpprime.c
@@ -394,7 +394,7 @@ mp_err mpp_make_prime(mp_int *start, mp_size nBits, mp_size strong,
{
mp_digit np;
mp_err res;
- unsigned int i = 0;
+ int i = 0;
mp_int trial;
mp_int q;
mp_size num_tests;