diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/math/ec_gfp | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency,
eg make_u32bit becomes make_uint32. The old typedefs remain for now
since probably lots of application code uses them.
Diffstat (limited to 'src/lib/math/ec_gfp')
-rw-r--r-- | src/lib/math/ec_gfp/curve_nistp.cpp | 216 | ||||
-rw-r--r-- | src/lib/math/ec_gfp/point_gfp.cpp | 26 | ||||
-rw-r--r-- | src/lib/math/ec_gfp/point_gfp.h | 6 |
3 files changed, 124 insertions, 124 deletions
diff --git a/src/lib/math/ec_gfp/curve_nistp.cpp b/src/lib/math/ec_gfp/curve_nistp.cpp index 176409dbf..fb94a81d2 100644 --- a/src/lib/math/ec_gfp/curve_nistp.cpp +++ b/src/lib/math/ec_gfp/curve_nistp.cpp @@ -89,12 +89,12 @@ namespace { * Treating this MPI as a sequence of 32-bit words in big-endian * order, return word i (or 0 if out of range) */ -inline u32bit get_u32bit(const BigInt& x, size_t i) +inline uint32_t get_uint32_t(const BigInt& x, size_t i) { #if (BOTAN_MP_WORD_BITS == 32) return x.word_at(i); #elif (BOTAN_MP_WORD_BITS == 64) - return static_cast<u32bit>(x.word_at(i/2) >> ((i % 2)*32)); + return static_cast<uint32_t>(x.word_at(i/2) >> ((i % 2)*32)); #else #error "Not implemented" #endif @@ -105,9 +105,9 @@ inline u32bit get_u32bit(const BigInt& x, size_t i) * order, set word i to the value x */ template<typename T> -inline void set_u32bit(BigInt& x, size_t i, T v_in) +inline void set_uint32_t(BigInt& x, size_t i, T v_in) { - const u32bit v = static_cast<u32bit>(v_in); + const uint32_t v = static_cast<uint32_t>(v_in); #if (BOTAN_MP_WORD_BITS == 32) x.set_word_at(i, v); #elif (BOTAN_MP_WORD_BITS == 64) @@ -129,56 +129,56 @@ const BigInt& prime_p192() void redc_p192(BigInt& x, secure_vector<word>& ws) { - const u32bit X6 = get_u32bit(x, 6); - const u32bit X7 = get_u32bit(x, 7); - const u32bit X8 = get_u32bit(x, 8); - const u32bit X9 = get_u32bit(x, 9); - const u32bit X10 = get_u32bit(x, 10); - const u32bit X11 = get_u32bit(x, 11); + const uint32_t X6 = get_uint32_t(x, 6); + const uint32_t X7 = get_uint32_t(x, 7); + const uint32_t X8 = get_uint32_t(x, 8); + const uint32_t X9 = get_uint32_t(x, 9); + const uint32_t X10 = get_uint32_t(x, 10); + const uint32_t X11 = get_uint32_t(x, 11); x.mask_bits(192); - u64bit S = 0; + uint64_t S = 0; - S += get_u32bit(x, 0); + S += get_uint32_t(x, 0); S += X6; S += X10; - set_u32bit(x, 0, S); + set_uint32_t(x, 0, S); S >>= 32; - S += get_u32bit(x, 1); + S += get_uint32_t(x, 1); S += X7; S += X11; - set_u32bit(x, 1, S); + set_uint32_t(x, 1, S); S >>= 32; - S += get_u32bit(x, 2); + S += get_uint32_t(x, 2); S += X6; S += X8; S += X10; - set_u32bit(x, 2, S); + set_uint32_t(x, 2, S); S >>= 32; - S += get_u32bit(x, 3); + S += get_uint32_t(x, 3); S += X7; S += X9; S += X11; - set_u32bit(x, 3, S); + set_uint32_t(x, 3, S); S >>= 32; - S += get_u32bit(x, 4); + S += get_uint32_t(x, 4); S += X8; S += X10; - set_u32bit(x, 4, S); + set_uint32_t(x, 4, S); S >>= 32; - S += get_u32bit(x, 5); + S += get_uint32_t(x, 5); S += X9; S += X11; - set_u32bit(x, 5, S); + set_uint32_t(x, 5, S); S >>= 32; - set_u32bit(x, 6, S); + set_uint32_t(x, 6, S); // No underflow possible @@ -193,13 +193,13 @@ const BigInt& prime_p224() void redc_p224(BigInt& x, secure_vector<word>& ws) { - const u32bit X7 = get_u32bit(x, 7); - const u32bit X8 = get_u32bit(x, 8); - const u32bit X9 = get_u32bit(x, 9); - const u32bit X10 = get_u32bit(x, 10); - const u32bit X11 = get_u32bit(x, 11); - const u32bit X12 = get_u32bit(x, 12); - const u32bit X13 = get_u32bit(x, 13); + const uint32_t X7 = get_uint32_t(x, 7); + const uint32_t X8 = get_uint32_t(x, 8); + const uint32_t X9 = get_uint32_t(x, 9); + const uint32_t X10 = get_uint32_t(x, 10); + const uint32_t X11 = get_uint32_t(x, 11); + const uint32_t X12 = get_uint32_t(x, 12); + const uint32_t X13 = get_uint32_t(x, 13); x.mask_bits(224); @@ -207,56 +207,56 @@ void redc_p224(BigInt& x, secure_vector<word>& ws) int64_t S = 0; - S += get_u32bit(x, 0); + S += get_uint32_t(x, 0); S += 1; S -= X7; S -= X11; - set_u32bit(x, 0, S); + set_uint32_t(x, 0, S); S >>= 32; - S += get_u32bit(x, 1); + S += get_uint32_t(x, 1); S -= X8; S -= X12; - set_u32bit(x, 1, S); + set_uint32_t(x, 1, S); S >>= 32; - S += get_u32bit(x, 2); + S += get_uint32_t(x, 2); S -= X9; S -= X13; - set_u32bit(x, 2, S); + set_uint32_t(x, 2, S); S >>= 32; - S += get_u32bit(x, 3); + S += get_uint32_t(x, 3); S += 0xFFFFFFFF; S += X7; S += X11; S -= X10; - set_u32bit(x, 3, S); + set_uint32_t(x, 3, S); S >>= 32; - S += get_u32bit(x, 4); + S += get_uint32_t(x, 4); S += 0xFFFFFFFF; S += X8; S += X12; S -= X11; - set_u32bit(x, 4, S); + set_uint32_t(x, 4, S); S >>= 32; - S += get_u32bit(x, 5); + S += get_uint32_t(x, 5); S += 0xFFFFFFFF; S += X9; S += X13; S -= X12; - set_u32bit(x, 5, S); + set_uint32_t(x, 5, S); S >>= 32; - S += get_u32bit(x, 6); + S += get_uint32_t(x, 6); S += 0xFFFFFFFF; S += X10; S -= X13; - set_u32bit(x, 6, S); + set_uint32_t(x, 6, S); S >>= 32; - set_u32bit(x, 7, S); + set_uint32_t(x, 7, S); BOTAN_ASSERT_EQUAL(S >> 32, 0, "No underflow"); @@ -271,14 +271,14 @@ const BigInt& prime_p256() void redc_p256(BigInt& x, secure_vector<word>& ws) { - const u32bit X8 = get_u32bit(x, 8); - const u32bit X9 = get_u32bit(x, 9); - const u32bit X10 = get_u32bit(x, 10); - const u32bit X11 = get_u32bit(x, 11); - const u32bit X12 = get_u32bit(x, 12); - const u32bit X13 = get_u32bit(x, 13); - const u32bit X14 = get_u32bit(x, 14); - const u32bit X15 = get_u32bit(x, 15); + const uint32_t X8 = get_uint32_t(x, 8); + const uint32_t X9 = get_uint32_t(x, 9); + const uint32_t X10 = get_uint32_t(x, 10); + const uint32_t X11 = get_uint32_t(x, 11); + const uint32_t X12 = get_uint32_t(x, 12); + const uint32_t X13 = get_uint32_t(x, 13); + const uint32_t X14 = get_uint32_t(x, 14); + const uint32_t X15 = get_uint32_t(x, 15); x.mask_bits(256); @@ -286,7 +286,7 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) // Adds 6 * P-256 to prevent underflow - S = get_u32bit(x, 0); + S = get_uint32_t(x, 0); S += 0xFFFFFFFA; S += X8; S += X9; @@ -294,10 +294,10 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S -= X12; S -= X13; S -= X14; - set_u32bit(x, 0, S); + set_uint32_t(x, 0, S); S >>= 32; - S += get_u32bit(x, 1); + S += get_uint32_t(x, 1); S += 0xFFFFFFFF; S += X9; S += X10; @@ -305,20 +305,20 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S -= X13; S -= X14; S -= X15; - set_u32bit(x, 1, S); + set_uint32_t(x, 1, S); S >>= 32; - S += get_u32bit(x, 2); + S += get_uint32_t(x, 2); S += 0xFFFFFFFF; S += X10; S += X11; S -= X13; S -= X14; S -= X15; - set_u32bit(x, 2, S); + set_uint32_t(x, 2, S); S >>= 32; - S += get_u32bit(x, 3); + S += get_uint32_t(x, 3); S += 5; S += X11; S += X11; @@ -328,10 +328,10 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S -= X15; S -= X8; S -= X9; - set_u32bit(x, 3, S); + set_uint32_t(x, 3, S); S >>= 32; - S += get_u32bit(x, 4); + S += get_uint32_t(x, 4); S += X12; S += X12; S += X13; @@ -339,10 +339,10 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S += X14; S -= X9; S -= X10; - set_u32bit(x, 4, S); + set_uint32_t(x, 4, S); S >>= 32; - S += get_u32bit(x, 5); + S += get_uint32_t(x, 5); S += X13; S += X13; S += X14; @@ -350,10 +350,10 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S += X15; S -= X10; S -= X11; - set_u32bit(x, 5, S); + set_uint32_t(x, 5, S); S >>= 32; - S += get_u32bit(x, 6); + S += get_uint32_t(x, 6); S += 6; S += X14; S += X14; @@ -363,10 +363,10 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S += X13; S -= X8; S -= X9; - set_u32bit(x, 6, S); + set_uint32_t(x, 6, S); S >>= 32; - S += get_u32bit(x, 7); + S += get_uint32_t(x, 7); S += 0xFFFFFFFA; S += X15; S += X15; @@ -376,11 +376,11 @@ void redc_p256(BigInt& x, secure_vector<word>& ws) S -= X11; S -= X12; S -= X13; - set_u32bit(x, 7, S); + set_uint32_t(x, 7, S); S >>= 32; S += 5; - set_u32bit(x, 8, S); + set_uint32_t(x, 8, S); BOTAN_ASSERT_EQUAL(S >> 32, 0, "No underflow"); @@ -414,51 +414,51 @@ const BigInt& prime_p384() void redc_p384(BigInt& x, secure_vector<word>& ws) { - const u32bit X12 = get_u32bit(x, 12); - const u32bit X13 = get_u32bit(x, 13); - const u32bit X14 = get_u32bit(x, 14); - const u32bit X15 = get_u32bit(x, 15); - const u32bit X16 = get_u32bit(x, 16); - const u32bit X17 = get_u32bit(x, 17); - const u32bit X18 = get_u32bit(x, 18); - const u32bit X19 = get_u32bit(x, 19); - const u32bit X20 = get_u32bit(x, 20); - const u32bit X21 = get_u32bit(x, 21); - const u32bit X22 = get_u32bit(x, 22); - const u32bit X23 = get_u32bit(x, 23); + const uint32_t X12 = get_uint32_t(x, 12); + const uint32_t X13 = get_uint32_t(x, 13); + const uint32_t X14 = get_uint32_t(x, 14); + const uint32_t X15 = get_uint32_t(x, 15); + const uint32_t X16 = get_uint32_t(x, 16); + const uint32_t X17 = get_uint32_t(x, 17); + const uint32_t X18 = get_uint32_t(x, 18); + const uint32_t X19 = get_uint32_t(x, 19); + const uint32_t X20 = get_uint32_t(x, 20); + const uint32_t X21 = get_uint32_t(x, 21); + const uint32_t X22 = get_uint32_t(x, 22); + const uint32_t X23 = get_uint32_t(x, 23); x.mask_bits(384); int64_t S = 0; // One copy of P-384 is added to prevent underflow - S = get_u32bit(x, 0); + S = get_uint32_t(x, 0); S += 0xFFFFFFFF; S += X12; S += X21; S += X20; S -= X23; - set_u32bit(x, 0, S); + set_uint32_t(x, 0, S); S >>= 32; - S += get_u32bit(x, 1); + S += get_uint32_t(x, 1); S += X13; S += X22; S += X23; S -= X12; S -= X20; - set_u32bit(x, 1, S); + set_uint32_t(x, 1, S); S >>= 32; - S += get_u32bit(x, 2); + S += get_uint32_t(x, 2); S += X14; S += X23; S -= X13; S -= X21; - set_u32bit(x, 2, S); + set_uint32_t(x, 2, S); S >>= 32; - S += get_u32bit(x, 3); + S += get_uint32_t(x, 3); S += 0xFFFFFFFF; S += X15; S += X12; @@ -467,10 +467,10 @@ void redc_p384(BigInt& x, secure_vector<word>& ws) S -= X14; S -= X22; S -= X23; - set_u32bit(x, 3, S); + set_uint32_t(x, 3, S); S >>= 32; - S += get_u32bit(x, 4); + S += get_uint32_t(x, 4); S += 0xFFFFFFFE; S += X21; S += X21; @@ -482,10 +482,10 @@ void redc_p384(BigInt& x, secure_vector<word>& ws) S -= X15; S -= X23; S -= X23; - set_u32bit(x, 4, S); + set_uint32_t(x, 4, S); S >>= 32; - S += get_u32bit(x, 5); + S += get_uint32_t(x, 5); S += 0xFFFFFFFF; S += X22; S += X22; @@ -495,10 +495,10 @@ void redc_p384(BigInt& x, secure_vector<word>& ws) S += X21; S += X23; S -= X16; - set_u32bit(x, 5, S); + set_uint32_t(x, 5, S); S >>= 32; - S += get_u32bit(x, 6); + S += get_uint32_t(x, 6); S += 0xFFFFFFFF; S += X23; S += X23; @@ -507,56 +507,56 @@ void redc_p384(BigInt& x, secure_vector<word>& ws) S += X14; S += X22; S -= X17; - set_u32bit(x, 6, S); + set_uint32_t(x, 6, S); S >>= 32; - S += get_u32bit(x, 7); + S += get_uint32_t(x, 7); S += 0xFFFFFFFF; S += X19; S += X16; S += X15; S += X23; S -= X18; - set_u32bit(x, 7, S); + set_uint32_t(x, 7, S); S >>= 32; - S += get_u32bit(x, 8); + S += get_uint32_t(x, 8); S += 0xFFFFFFFF; S += X20; S += X17; S += X16; S -= X19; - set_u32bit(x, 8, S); + set_uint32_t(x, 8, S); S >>= 32; - S += get_u32bit(x, 9); + S += get_uint32_t(x, 9); S += 0xFFFFFFFF; S += X21; S += X18; S += X17; S -= X20; - set_u32bit(x, 9, S); + set_uint32_t(x, 9, S); S >>= 32; - S += get_u32bit(x, 10); + S += get_uint32_t(x, 10); S += 0xFFFFFFFF; S += X22; S += X19; S += X18; S -= X21; - set_u32bit(x, 10, S); + set_uint32_t(x, 10, S); S >>= 32; - S += get_u32bit(x, 11); + S += get_uint32_t(x, 11); S += 0xFFFFFFFF; S += X23; S += X20; S += X19; S -= X22; - set_u32bit(x, 11, S); + set_uint32_t(x, 11, S); S >>= 32; BOTAN_ASSERT_EQUAL(S >> 32, 0, "No underflow"); - set_u32bit(x, 12, S); + set_uint32_t(x, 12, S); #if 0 if(S >= 2) diff --git a/src/lib/math/ec_gfp/point_gfp.cpp b/src/lib/math/ec_gfp/point_gfp.cpp index f15911db0..bb446566e 100644 --- a/src/lib/math/ec_gfp/point_gfp.cpp +++ b/src/lib/math/ec_gfp/point_gfp.cpp @@ -406,7 +406,7 @@ PointGFp Blinded_Point_Multiply::blinded_multiply(const BigInt& scalar_in, if(windows > 0) { windows--; - const u32bit nibble = scalar.get_substring(windows*m_h, m_h); + const uint32_t nibble = scalar.get_substring(windows*m_h, m_h); R.add(m_U[nibble], m_ws); /* @@ -421,7 +421,7 @@ PointGFp Blinded_Point_Multiply::blinded_multiply(const BigInt& scalar_in, for(size_t i = 0; i != m_h; ++i) R.mult2(m_ws); - const u32bit inner_nibble = scalar.get_substring((windows-1)*m_h, m_h); + const uint32_t inner_nibble = scalar.get_substring((windows-1)*m_h, m_h); R.add(m_U[inner_nibble], m_ws); windows--; } @@ -513,22 +513,22 @@ bool PointGFp::operator==(const PointGFp& other) const } // encoding and decoding -secure_vector<byte> EC2OSP(const PointGFp& point, byte format) +secure_vector<uint8_t> EC2OSP(const PointGFp& point, uint8_t format) { if(point.is_zero()) - return secure_vector<byte>(1); // single 0 byte + return secure_vector<uint8_t>(1); // single 0 byte const size_t p_bytes = point.get_curve().get_p().bytes(); BigInt x = point.get_affine_x(); BigInt y = point.get_affine_y(); - secure_vector<byte> bX = BigInt::encode_1363(x, p_bytes); - secure_vector<byte> bY = BigInt::encode_1363(y, p_bytes); + secure_vector<uint8_t> bX = BigInt::encode_1363(x, p_bytes); + secure_vector<uint8_t> bY = BigInt::encode_1363(y, p_bytes); if(format == PointGFp::UNCOMPRESSED) { - secure_vector<byte> result; + secure_vector<uint8_t> result; result.push_back(0x04); result += bX; @@ -538,8 +538,8 @@ secure_vector<byte> EC2OSP(const PointGFp& point, byte format) } else if(format == PointGFp::COMPRESSED) { - secure_vector<byte> result; - result.push_back(0x02 | static_cast<byte>(y.get_bit(0))); + secure_vector<uint8_t> result; + result.push_back(0x02 | static_cast<uint8_t>(y.get_bit(0))); result += bX; @@ -547,8 +547,8 @@ secure_vector<byte> EC2OSP(const PointGFp& point, byte format) } else if(format == PointGFp::HYBRID) { - secure_vector<byte> result; - result.push_back(0x06 | static_cast<byte>(y.get_bit(0))); + secure_vector<uint8_t> result; + result.push_back(0x06 | static_cast<uint8_t>(y.get_bit(0))); result += bX; result += bY; @@ -587,13 +587,13 @@ BigInt decompress_point(bool yMod2, } -PointGFp OS2ECP(const byte data[], size_t data_len, +PointGFp OS2ECP(const uint8_t data[], size_t data_len, const CurveGFp& curve) { if(data_len <= 1) return PointGFp(curve); // return zero - const byte pc = data[0]; + const uint8_t pc = data[0]; BigInt x, y; diff --git a/src/lib/math/ec_gfp/point_gfp.h b/src/lib/math/ec_gfp/point_gfp.h index c64963683..6f4c7e5f9 100644 --- a/src/lib/math/ec_gfp/point_gfp.h +++ b/src/lib/math/ec_gfp/point_gfp.h @@ -274,13 +274,13 @@ inline PointGFp operator*(const PointGFp& point, const BigInt& scalar) } // encoding and decoding -secure_vector<byte> BOTAN_DLL EC2OSP(const PointGFp& point, byte format); +secure_vector<uint8_t> BOTAN_DLL EC2OSP(const PointGFp& point, uint8_t format); -PointGFp BOTAN_DLL OS2ECP(const byte data[], size_t data_len, +PointGFp BOTAN_DLL OS2ECP(const uint8_t data[], size_t data_len, const CurveGFp& curve); template<typename Alloc> -PointGFp OS2ECP(const std::vector<byte, Alloc>& data, const CurveGFp& curve) +PointGFp OS2ECP(const std::vector<uint8_t, Alloc>& data, const CurveGFp& curve) { return OS2ECP(data.data(), data.size(), curve); } /** |