aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/mac/poly1305/poly1305.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mac/poly1305/poly1305.cpp')
-rw-r--r--src/lib/mac/poly1305/poly1305.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/lib/mac/poly1305/poly1305.cpp b/src/lib/mac/poly1305/poly1305.cpp
index 0a62808f6..9fe0bad0a 100644
--- a/src/lib/mac/poly1305/poly1305.cpp
+++ b/src/lib/mac/poly1305/poly1305.cpp
@@ -17,11 +17,11 @@ namespace Botan {
namespace {
-void poly1305_init(secure_vector<u64bit>& X, const byte key[32])
+void poly1305_init(secure_vector<uint64_t>& X, const uint8_t key[32])
{
/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
- const u64bit t0 = load_le<u64bit>(key, 0);
- const u64bit t1 = load_le<u64bit>(key, 1);
+ const uint64_t t0 = load_le<uint64_t>(key, 0);
+ const uint64_t t1 = load_le<uint64_t>(key, 1);
X[0] = ( t0 ) & 0xffc0fffffff;
X[1] = ((t0 >> 44) | (t1 << 20)) & 0xfffffc0ffff;
@@ -33,34 +33,34 @@ void poly1305_init(secure_vector<u64bit>& X, const byte key[32])
X[5] = 0;
/* save pad for later */
- X[6] = load_le<u64bit>(key, 2);
- X[7] = load_le<u64bit>(key, 3);
+ X[6] = load_le<uint64_t>(key, 2);
+ X[7] = load_le<uint64_t>(key, 3);
}
-void poly1305_blocks(secure_vector<u64bit>& X, const byte *m, size_t blocks, bool is_final = false)
+void poly1305_blocks(secure_vector<uint64_t>& X, const uint8_t *m, size_t blocks, bool is_final = false)
{
#if !defined(BOTAN_TARGET_HAS_NATIVE_UINT128)
typedef donna128 uint128_t;
#endif
- const u64bit hibit = is_final ? 0 : (static_cast<u64bit>(1) << 40); /* 1 << 128 */
+ const uint64_t hibit = is_final ? 0 : (static_cast<uint64_t>(1) << 40); /* 1 << 128 */
- const u64bit r0 = X[0];
- const u64bit r1 = X[1];
- const u64bit r2 = X[2];
+ const uint64_t r0 = X[0];
+ const uint64_t r1 = X[1];
+ const uint64_t r2 = X[2];
- u64bit h0 = X[3+0];
- u64bit h1 = X[3+1];
- u64bit h2 = X[3+2];
+ uint64_t h0 = X[3+0];
+ uint64_t h1 = X[3+1];
+ uint64_t h2 = X[3+2];
- const u64bit s1 = r1 * (5 << 2);
- const u64bit s2 = r2 * (5 << 2);
+ const uint64_t s1 = r1 * (5 << 2);
+ const uint64_t s2 = r2 * (5 << 2);
while(blocks--)
{
/* h += m[i] */
- const u64bit t0 = load_le<u64bit>(m, 0);
- const u64bit t1 = load_le<u64bit>(m, 1);
+ const uint64_t t0 = load_le<uint64_t>(m, 0);
+ const uint64_t t1 = load_le<uint64_t>(m, 1);
h0 += (( t0 ) & 0xfffffffffff);
h1 += (((t0 >> 44) | (t1 << 20)) & 0xfffffffffff);
@@ -72,7 +72,7 @@ void poly1305_blocks(secure_vector<u64bit>& X, const byte *m, size_t blocks, boo
uint128_t d2 = uint128_t(h0) * r2 + uint128_t(h1) * r1 + uint128_t(h2) * r0;
/* (partial) h %= p */
- u64bit c = carry_shift(d0, 44); h0 = d0 & 0xfffffffffff;
+ uint64_t c = carry_shift(d0, 44); h0 = d0 & 0xfffffffffff;
d1 += c; c = carry_shift(d1, 44); h1 = d1 & 0xfffffffffff;
d2 += c; c = carry_shift(d2, 42); h2 = d2 & 0x3ffffffffff;
h0 += c * 5; c = carry_shift(h0, 44); h0 = h0 & 0xfffffffffff;
@@ -86,14 +86,14 @@ void poly1305_blocks(secure_vector<u64bit>& X, const byte *m, size_t blocks, boo
X[3+2] = h2;
}
-void poly1305_finish(secure_vector<u64bit>& X, byte mac[16])
+void poly1305_finish(secure_vector<uint64_t>& X, uint8_t mac[16])
{
/* fully carry h */
- u64bit h0 = X[3+0];
- u64bit h1 = X[3+1];
- u64bit h2 = X[3+2];
+ uint64_t h0 = X[3+0];
+ uint64_t h1 = X[3+1];
+ uint64_t h2 = X[3+2];
- u64bit c;
+ uint64_t c;
c = (h1 >> 44); h1 &= 0xfffffffffff;
h2 += c; c = (h2 >> 42); h2 &= 0x3ffffffffff;
h0 += c * 5; c = (h0 >> 44); h0 &= 0xfffffffffff;
@@ -103,12 +103,12 @@ void poly1305_finish(secure_vector<u64bit>& X, byte mac[16])
h1 += c;
/* compute h + -p */
- u64bit g0 = h0 + 5; c = (g0 >> 44); g0 &= 0xfffffffffff;
- u64bit g1 = h1 + c; c = (g1 >> 44); g1 &= 0xfffffffffff;
- u64bit g2 = h2 + c - (static_cast<u64bit>(1) << 42);
+ uint64_t g0 = h0 + 5; c = (g0 >> 44); g0 &= 0xfffffffffff;
+ uint64_t g1 = h1 + c; c = (g1 >> 44); g1 &= 0xfffffffffff;
+ uint64_t g2 = h2 + c - (static_cast<uint64_t>(1) << 42);
/* select h if h < p, or h + -p if h >= p */
- c = (g2 >> ((sizeof(u64bit) * 8) - 1)) - 1;
+ c = (g2 >> ((sizeof(uint64_t) * 8) - 1)) - 1;
g0 &= c;
g1 &= c;
g2 &= c;
@@ -118,8 +118,8 @@ void poly1305_finish(secure_vector<u64bit>& X, byte mac[16])
h2 = (h2 & c) | g2;
/* h = (h + pad) */
- const u64bit t0 = X[6];
- const u64bit t1 = X[7];
+ const uint64_t t0 = X[6];
+ const uint64_t t1 = X[7];
h0 += (( t0 ) & 0xfffffffffff) ; c = (h0 >> 44); h0 &= 0xfffffffffff;
h1 += (((t0 >> 44) | (t1 << 20)) & 0xfffffffffff) + c; c = (h1 >> 44); h1 &= 0xfffffffffff;
@@ -144,7 +144,7 @@ void Poly1305::clear()
m_buf_pos = 0;
}
-void Poly1305::key_schedule(const byte key[], size_t)
+void Poly1305::key_schedule(const uint8_t key[], size_t)
{
m_buf_pos = 0;
m_buf.resize(16);
@@ -153,7 +153,7 @@ void Poly1305::key_schedule(const byte key[], size_t)
poly1305_init(m_poly, key);
}
-void Poly1305::add_data(const byte input[], size_t length)
+void Poly1305::add_data(const uint8_t input[], size_t length)
{
BOTAN_ASSERT_EQUAL(m_poly.size(), 8, "Initialized");
@@ -180,7 +180,7 @@ void Poly1305::add_data(const byte input[], size_t length)
m_buf_pos += remaining;
}
-void Poly1305::final_result(byte out[])
+void Poly1305::final_result(uint8_t out[])
{
BOTAN_ASSERT_EQUAL(m_poly.size(), 8, "Initialized");