diff options
author | lloyd <[email protected]> | 2010-09-13 15:21:31 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-13 15:21:31 +0000 |
commit | 4a7e9edcc92b08a285ea24549fd8c813d10b63b9 (patch) | |
tree | 569e357cbc1bd2b195c1b10b281f6c0bbf01fd33 | |
parent | 27d79c87365105d6128afe9eaf8a82383976ed44 (diff) |
First set of changes for avoiding use implicit vector->pointer conversions
28 files changed, 163 insertions, 131 deletions
diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index 1bbcd72c2..f2873c177 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -103,10 +103,10 @@ u32bit find_eoc(DataSource* ber) while(true) { - const u32bit got = ber->peek(buffer, buffer.size(), data.size()); + const u32bit got = ber->peek(&buffer[0], buffer.size(), data.size()); if(got == 0) break; - data.append(buffer, got); + data.append(&buffer[0], got); } DataSource_Memory source(data); @@ -206,7 +206,7 @@ BER_Object BER_Decoder::get_next_object() u32bit length = decode_length(source); next.value.resize(length); - if(source->read(next.value, length) != length) + if(source->read(&next.value[0], length) != length) throw BER_Decoding_Error("Value truncated"); if(next.type_tag == EOC && next.class_tag == UNIVERSAL) @@ -234,7 +234,7 @@ BER_Decoder BER_Decoder::start_cons(ASN1_Tag type_tag, BER_Object obj = get_next_object(); obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED)); - BER_Decoder result(obj.value, obj.value.size()); + BER_Decoder result(&obj.value[0], obj.value.size()); result.parent = this; return result; } @@ -415,7 +415,7 @@ BER_Decoder& BER_Decoder::decode(BigInt& out, obj.value[j] = ~obj.value[j]; } - out = BigInt(obj.value, obj.value.size()); + out = BigInt(&obj.value[0], obj.value.size()); if(negative) out.flip_sign(); diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp index 2485fc1a1..93f7f4363 100644 --- a/src/block/aes/aes.cpp +++ b/src/block/aes/aes.cpp @@ -661,12 +661,12 @@ void AES::key_schedule(const byte key[], u32bit length) for(u32bit j = 0; j != 4; ++j) { - store_be(XEK[j+4*ROUNDS], ME + 4*j); - store_be(XEK[j], MD + 4*j); + store_be(XEK[j+4*ROUNDS], &ME[4*j]); + store_be(XEK[j], &MD[4*j]); } - EK.copy(XEK, length + 24); - DK.copy(XDK, length + 24); + EK.copy(&XEK[0], length + 24); + DK.copy(&XDK[0], length + 24); } /* diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp index d0b182a84..6e4ad5b28 100644 --- a/src/block/blowfish/blowfish.cpp +++ b/src/block/blowfish/blowfish.cpp @@ -15,10 +15,10 @@ namespace Botan { */ void Blowfish::encrypt_n(const byte in[], byte out[], u32bit blocks) const { - const u32bit* S1 = S + 0; - const u32bit* S2 = S + 256; - const u32bit* S3 = S + 512; - const u32bit* S4 = S + 768; + const u32bit* S1 = &S[0]; + const u32bit* S2 = &S[256]; + const u32bit* S3 = &S[512]; + const u32bit* S4 = &S[768]; for(u32bit i = 0; i != blocks; ++i) { @@ -50,10 +50,10 @@ void Blowfish::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void Blowfish::decrypt_n(const byte in[], byte out[], u32bit blocks) const { - const u32bit* S1 = S + 0; - const u32bit* S2 = S + 256; - const u32bit* S3 = S + 512; - const u32bit* S4 = S + 768; + const u32bit* S1 = &S[0]; + const u32bit* S2 = &S[256]; + const u32bit* S3 = &S[512]; + const u32bit* S4 = &S[768]; for(u32bit i = 0; i != blocks; ++i) { @@ -92,22 +92,22 @@ void Blowfish::key_schedule(const byte key[], u32bit length) key[(k+2) % length], key[(k+3) % length]); u32bit L = 0, R = 0; - generate_sbox(P, 18, L, R); - generate_sbox(S, 1024, L, R); + generate_sbox(P, L, R); + generate_sbox(S, L, R); } /* * Generate one of the Sboxes */ -void Blowfish::generate_sbox(u32bit Box[], u32bit size, +void Blowfish::generate_sbox(MemoryRegion<u32bit>& box, u32bit& L, u32bit& R) const { - const u32bit* S1 = S + 0; - const u32bit* S2 = S + 256; - const u32bit* S3 = S + 512; - const u32bit* S4 = S + 768; + const u32bit* S1 = &S[0]; + const u32bit* S2 = &S[256]; + const u32bit* S3 = &S[512]; + const u32bit* S4 = &S[768]; - for(u32bit j = 0; j != size; j += 2) + for(u32bit j = 0; j != box.size(); j += 2) { for(u32bit k = 0; k != 16; k += 2) { @@ -121,7 +121,8 @@ void Blowfish::generate_sbox(u32bit Box[], u32bit size, } u32bit T = R; R = L ^ P[16]; L = T ^ P[17]; - Box[j] = L; Box[j+1] = R; + box[j] = L; + box[j+1] = R; } } diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h index a178ec488..88122aed8 100644 --- a/src/block/blowfish/blowfish.h +++ b/src/block/blowfish/blowfish.h @@ -28,7 +28,8 @@ class BOTAN_DLL Blowfish : public BlockCipher Blowfish() : BlockCipher(8, 1, 56) {} private: void key_schedule(const byte[], u32bit); - void generate_sbox(u32bit[], u32bit, u32bit&, u32bit&) const; + void generate_sbox(MemoryRegion<u32bit>& box, + u32bit& L, u32bit& R) const; static const u32bit P_INIT[18]; static const u32bit S_INIT[1024]; diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp index cabde4b4f..b68b7abd7 100644 --- a/src/block/cast/cast128.cpp +++ b/src/block/cast/cast128.cpp @@ -123,8 +123,8 @@ void CAST_128::key_schedule(const byte key[], u32bit length) for(u32bit j = 0; j != length; ++j) X[j/4] = (X[j/4] << 8) + key[j]; - key_schedule(MK, X); - key_schedule(RK, X); + cast_ks(MK, X); + cast_ks(RK, X); for(u32bit j = 0; j != 16; ++j) RK[j] %= 32; @@ -133,7 +133,8 @@ void CAST_128::key_schedule(const byte key[], u32bit length) /* * S-Box Based Key Expansion */ -void CAST_128::key_schedule(u32bit K[16], u32bit X[4]) +void CAST_128::cast_ks(MemoryRegion<u32bit>& K, + MemoryRegion<u32bit>& X) { class ByteReader { @@ -145,7 +146,7 @@ void CAST_128::key_schedule(u32bit K[16], u32bit X[4]) }; SecureVector<u32bit, 4> Z; - ByteReader x(X), z(Z); + ByteReader x(&X[0]), z(&Z[0]); Z[0] = X[0] ^ S5[x(13)] ^ S6[x(15)] ^ S7[x(12)] ^ S8[x(14)] ^ S7[x( 8)]; Z[1] = X[2] ^ S5[z( 0)] ^ S6[z( 2)] ^ S7[z( 1)] ^ S8[z( 3)] ^ S8[x(10)]; diff --git a/src/block/cast/cast128.h b/src/block/cast/cast128.h index e5d4a884b..425eb46cc 100644 --- a/src/block/cast/cast128.h +++ b/src/block/cast/cast128.h @@ -29,7 +29,8 @@ class BOTAN_DLL CAST_128 : public BlockCipher private: void key_schedule(const byte[], u32bit); - static void key_schedule(u32bit[16], u32bit[4]); + static void cast_ks(MemoryRegion<u32bit>& ks, + MemoryRegion<u32bit>& user_key); static const u32bit S5[256]; static const u32bit S6[256]; diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp index a24a1d445..37424cd35 100644 --- a/src/block/des/des.cpp +++ b/src/block/des/des.cpp @@ -152,7 +152,7 @@ void DES::encrypt_n(const byte in[], byte out[], u32bit blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_encrypt(L, R, round_key); + des_encrypt(L, R, &round_key[0]); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | @@ -182,7 +182,7 @@ void DES::decrypt_n(const byte in[], byte out[], u32bit blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_decrypt(L, R, round_key); + des_decrypt(L, R, &round_key[0]); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | @@ -221,9 +221,9 @@ void TripleDES::encrypt_n(const byte in[], byte out[], u32bit blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_encrypt(L, R, round_key); - des_decrypt(R, L, round_key + 32); - des_encrypt(L, R, round_key + 64); + des_encrypt(L, R, &round_key[0]); + des_decrypt(R, L, &round_key[32]); + des_encrypt(L, R, &round_key[64]); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | @@ -254,9 +254,9 @@ void TripleDES::decrypt_n(const byte in[], byte out[], u32bit blocks) const u32bit L = static_cast<u32bit>(T >> 32); u32bit R = static_cast<u32bit>(T); - des_decrypt(L, R, round_key + 64); - des_encrypt(R, L, round_key + 32); - des_decrypt(L, R, round_key); + des_decrypt(L, R, &round_key[64]); + des_encrypt(R, L, &round_key[32]); + des_decrypt(L, R, &round_key[0]); T = (DES_FPTAB1[get_byte(0, L)] << 5) | (DES_FPTAB1[get_byte(1, L)] << 3) | (DES_FPTAB1[get_byte(2, L)] << 1) | (DES_FPTAB2[get_byte(3, L)] << 1) | diff --git a/src/block/idea/idea.cpp b/src/block/idea/idea.cpp index 0c5dfed42..7673ead7e 100644 --- a/src/block/idea/idea.cpp +++ b/src/block/idea/idea.cpp @@ -111,7 +111,7 @@ void idea_op(const byte in[], byte out[], u32bit blocks, const u16bit K[52]) */ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const { - idea_op(in, out, blocks, EK); + idea_op(in, out, blocks, &EK[0]); } /* @@ -119,7 +119,7 @@ void IDEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void IDEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const { - idea_op(in, out, blocks, DK); + idea_op(in, out, blocks, &DK[0]); } /* diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp index a7ded37e1..857869115 100644 --- a/src/block/idea_sse2/idea_sse2.cpp +++ b/src/block/idea_sse2/idea_sse2.cpp @@ -196,9 +196,11 @@ void idea_op_8(const byte in[64], byte out[64], const u16bit EK[52]) */ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u16bit* KS = &this->get_EK()[0]; + while(blocks >= 8) { - idea_op_8(in, out, this->get_EK()); + idea_op_8(in, out, KS); in += 8 * BLOCK_SIZE; out += 8 * BLOCK_SIZE; blocks -= 8; @@ -213,9 +215,11 @@ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void IDEA_SSE2::decrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u16bit* KS = &this->get_DK()[0]; + while(blocks >= 8) { - idea_op_8(in, out, this->get_DK()); + idea_op_8(in, out, KS); in += 8 * BLOCK_SIZE; out += 8 * BLOCK_SIZE; blocks -= 8; diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp index d7f981b20..8dcdff716 100644 --- a/src/block/kasumi/kasumi.cpp +++ b/src/block/kasumi/kasumi.cpp @@ -120,7 +120,7 @@ void KASUMI::encrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 0; j != 8; j += 2) { - const u16bit* K = EK + 8*j; + const u16bit* K = &EK[8*j]; u16bit R = B1 ^ (rotate_left(B0, 1) & K[0]); u16bit L = B0 ^ (rotate_left(R, 1) | K[1]); @@ -164,7 +164,7 @@ void KASUMI::decrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 0; j != 8; j += 2) { - const u16bit* K = EK + 8*(6-j); + const u16bit* K = &EK[8*(6-j)]; u16bit L = B2, R = B3; diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp index 45e051ada..9d0dff297 100644 --- a/src/block/lion/lion.cpp +++ b/src/block/lion/lion.cpp @@ -16,11 +16,12 @@ namespace Botan { */ void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const { - SecureVector<byte> buffer(LEFT_SIZE); + SecureVector<byte> buffer_vec(LEFT_SIZE); + byte* buffer = &buffer_vec[0]; for(u32bit i = 0; i != blocks; ++i) { - xor_buf(buffer, in, key1, LEFT_SIZE); + xor_buf(buffer, in, &key1[0], LEFT_SIZE); cipher->set_key(buffer, LEFT_SIZE); cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE); @@ -28,7 +29,7 @@ void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const hash->final(buffer); xor_buf(out, in, buffer, LEFT_SIZE); - xor_buf(buffer, out, key2, LEFT_SIZE); + xor_buf(buffer, out, &key2[0], LEFT_SIZE); cipher->set_key(buffer, LEFT_SIZE); cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE); @@ -42,11 +43,12 @@ void Lion::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void Lion::decrypt_n(const byte in[], byte out[], u32bit blocks) const { - SecureVector<byte> buffer(LEFT_SIZE); + SecureVector<byte> buffer_vec(LEFT_SIZE); + byte* buffer = &buffer_vec[0]; for(u32bit i = 0; i != blocks; ++i) { - xor_buf(buffer, in, key2, LEFT_SIZE); + xor_buf(buffer, in, &key2[0], LEFT_SIZE); cipher->set_key(buffer, LEFT_SIZE); cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE); @@ -54,7 +56,7 @@ void Lion::decrypt_n(const byte in[], byte out[], u32bit blocks) const hash->final(buffer); xor_buf(out, in, buffer, LEFT_SIZE); - xor_buf(buffer, out, key1, LEFT_SIZE); + xor_buf(buffer, out, &key1[0], LEFT_SIZE); cipher->set_key(buffer, LEFT_SIZE); cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE); diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp index 4dd0d5c8a..99f8e6da1 100644 --- a/src/block/lubyrack/lubyrack.cpp +++ b/src/block/lubyrack/lubyrack.cpp @@ -15,29 +15,30 @@ namespace Botan { */ void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u32bit len = hash->OUTPUT_LENGTH; + + SecureVector<byte> buffer(len); + for(u32bit i = 0; i != blocks; ++i) { - const u32bit len = hash->OUTPUT_LENGTH; - - SecureVector<byte> buffer(len); hash->update(K1); hash->update(in, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out + len, in + len, buffer, len); hash->update(K2); hash->update(out + len, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out, in, buffer, len); hash->update(K1); hash->update(out, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out + len, buffer, len); hash->update(K2); hash->update(out + len, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out, buffer, len); in += BLOCK_SIZE; @@ -50,29 +51,30 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void LubyRackoff::decrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u32bit len = hash->OUTPUT_LENGTH; + + SecureVector<byte> buffer(len); + for(u32bit i = 0; i != blocks; ++i) { - const u32bit len = hash->OUTPUT_LENGTH; - - SecureVector<byte> buffer(len); hash->update(K2); hash->update(in + len, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out, in, buffer, len); hash->update(K1); hash->update(out, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out + len, in + len, buffer, len); hash->update(K2); hash->update(out + len, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out, buffer, len); hash->update(K1); hash->update(out, len); - hash->final(buffer); + hash->final(&buffer[0]); xor_buf(out + len, buffer, len); in += BLOCK_SIZE; diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp index 9ab4d11f4..d5d3513a2 100644 --- a/src/block/misty1/misty1.cpp +++ b/src/block/misty1/misty1.cpp @@ -113,7 +113,7 @@ void MISTY1::encrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 0; j != 12; j += 3) { - const u16bit* RK = EK + 8 * j; + const u16bit* RK = &EK[8 * j]; B1 ^= B0 & RK[0]; B0 ^= B1 | RK[1]; @@ -163,7 +163,7 @@ void MISTY1::decrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 0; j != 12; j += 3) { - const u16bit* RK = DK + 8 * j; + const u16bit* RK = &DK[8 * j]; B2 ^= B3 | RK[0]; B3 ^= B2 & RK[1]; diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp index 95178a62b..a24153a29 100644 --- a/src/block/noekeon/noekeon.cpp +++ b/src/block/noekeon/noekeon.cpp @@ -96,7 +96,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 0; j != 16; ++j) { A0 ^= RC[j]; - theta(A0, A1, A2, A3, EK); + theta(A0, A1, A2, A3, &EK[0]); A1 = rotate_left(A1, 1); A2 = rotate_left(A2, 5); @@ -110,7 +110,7 @@ void Noekeon::encrypt_n(const byte in[], byte out[], u32bit blocks) const } A0 ^= RC[16]; - theta(A0, A1, A2, A3, EK); + theta(A0, A1, A2, A3, &EK[0]); store_be(out, A0, A1, A2, A3); @@ -133,7 +133,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], u32bit blocks) const for(u32bit j = 16; j != 0; --j) { - theta(A0, A1, A2, A3, DK); + theta(A0, A1, A2, A3, &DK[0]); A0 ^= RC[j]; A1 = rotate_left(A1, 1); @@ -147,7 +147,7 @@ void Noekeon::decrypt_n(const byte in[], byte out[], u32bit blocks) const A3 = rotate_right(A3, 2); } - theta(A0, A1, A2, A3, DK); + theta(A0, A1, A2, A3, &DK[0]); A0 ^= RC[0]; store_be(out, A0, A1, A2, A3); diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp index 3114c6055..4657d7b6c 100644 --- a/src/block/rc2/rc2.cpp +++ b/src/block/rc2/rc2.cpp @@ -133,8 +133,7 @@ void RC2::key_schedule(const byte key[], u32bit length) for(s32bit j = 127-length; j >= 0; --j) L[j] = TABLE[L[j+1] ^ L[j+length]]; - for(u32bit j = 0; j != 64; ++j) - K[j] = load_le<u16bit>(L, j); + load_le<u16bit>(&K[0], &L[0], 64); } /* diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp index b93326e58..4979ecbab 100644 --- a/src/block/serpent/serpent.cpp +++ b/src/block/serpent/serpent.cpp @@ -379,7 +379,7 @@ void Serpent::key_schedule(const byte key[], u32bit length) SBoxE8(W[120],W[121],W[122],W[123]); SBoxE7(W[124],W[125],W[126],W[127]); SBoxE6(W[128],W[129],W[130],W[131]); SBoxE5(W[132],W[133],W[134],W[135]); SBoxE4(W[136],W[137],W[138],W[139]); - round_key.copy(W + 8, 132); + round_key.copy(&W[8], 132); } } diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp index c64514de1..a4143804a 100644 --- a/src/block/serpent_simd/serp_simd.cpp +++ b/src/block/serpent_simd/serp_simd.cpp @@ -180,9 +180,11 @@ void serpent_decrypt_4(const byte in[64], */ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u32bit* KS = &(this->get_round_keys()[0]); + while(blocks >= 4) { - serpent_encrypt_4(in, out, this->get_round_keys()); + serpent_encrypt_4(in, out, KS); in += 4 * BLOCK_SIZE; out += 4 * BLOCK_SIZE; blocks -= 4; @@ -197,9 +199,11 @@ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void Serpent_SIMD::decrypt_n(const byte in[], byte out[], u32bit blocks) const { + const u32bit* KS = &(this->get_round_keys()[0]); + while(blocks >= 4) { - serpent_decrypt_4(in, out, this->get_round_keys()); + serpent_decrypt_4(in, out, KS); in += 4 * BLOCK_SIZE; out += 4 * BLOCK_SIZE; blocks -= 4; diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp index dda984e4c..2a1901230 100644 --- a/src/block/skipjack/skipjack.cpp +++ b/src/block/skipjack/skipjack.cpp @@ -77,6 +77,8 @@ void step_Bi(u16bit& W2, u16bit& W3, u32bit round, const byte FTAB[]) */ void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const { + const byte* ftab = &FTAB[0]; + for(u32bit i = 0; i != blocks; ++i) { u16bit W1 = load_le<u16bit>(in, 3); @@ -84,25 +86,25 @@ void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const u16bit W3 = load_le<u16bit>(in, 1); u16bit W4 = load_le<u16bit>(in, 0); - step_A(W1, W4, 1, FTAB); step_A(W4, W3, 2, FTAB); - step_A(W3, W2, 3, FTAB); step_A(W2, W1, 4, FTAB); - step_A(W1, W4, 5, FTAB); step_A(W4, W3, 6, FTAB); - step_A(W3, W2, 7, FTAB); step_A(W2, W1, 8, FTAB); + step_A(W1, W4, 1, ftab); step_A(W4, W3, 2, ftab); + step_A(W3, W2, 3, ftab); step_A(W2, W1, 4, ftab); + step_A(W1, W4, 5, ftab); step_A(W4, W3, 6, ftab); + step_A(W3, W2, 7, ftab); step_A(W2, W1, 8, ftab); - step_B(W1, W2, 9, FTAB); step_B(W4, W1, 10, FTAB); - step_B(W3, W4, 11, FTAB); step_B(W2, W3, 12, FTAB); - step_B(W1, W2, 13, FTAB); step_B(W4, W1, 14, FTAB); - step_B(W3, W4, 15, FTAB); step_B(W2, W3, 16, FTAB); + step_B(W1, W2, 9, ftab); step_B(W4, W1, 10, ftab); + step_B(W3, W4, 11, ftab); step_B(W2, W3, 12, ftab); + step_B(W1, W2, 13, ftab); step_B(W4, W1, 14, ftab); + step_B(W3, W4, 15, ftab); step_B(W2, W3, 16, ftab); - step_A(W1, W4, 17, FTAB); step_A(W4, W3, 18, FTAB); - step_A(W3, W2, 19, FTAB); step_A(W2, W1, 20, FTAB); - step_A(W1, W4, 21, FTAB); step_A(W4, W3, 22, FTAB); - step_A(W3, W2, 23, FTAB); step_A(W2, W1, 24, FTAB); + step_A(W1, W4, 17, ftab); step_A(W4, W3, 18, ftab); + step_A(W3, W2, 19, ftab); step_A(W2, W1, 20, ftab); + step_A(W1, W4, 21, ftab); step_A(W4, W3, 22, ftab); + step_A(W3, W2, 23, ftab); step_A(W2, W1, 24, ftab); - step_B(W1, W2, 25, FTAB); step_B(W4, W1, 26, FTAB); - step_B(W3, W4, 27, FTAB); step_B(W2, W3, 28, FTAB); - step_B(W1, W2, 29, FTAB); step_B(W4, W1, 30, FTAB); - step_B(W3, W4, 31, FTAB); step_B(W2, W3, 32, FTAB); + step_B(W1, W2, 25, ftab); step_B(W4, W1, 26, ftab); + step_B(W3, W4, 27, ftab); step_B(W2, W3, 28, ftab); + step_B(W1, W2, 29, ftab); step_B(W4, W1, 30, ftab); + step_B(W3, W4, 31, ftab); step_B(W2, W3, 32, ftab); store_le(out, W4, W3, W2, W1); @@ -116,6 +118,8 @@ void Skipjack::encrypt_n(const byte in[], byte out[], u32bit blocks) const */ void Skipjack::decrypt_n(const byte in[], byte out[], u32bit blocks) const { + const byte* ftab = &FTAB[0]; + for(u32bit i = 0; i != blocks; ++i) { u16bit W1 = load_le<u16bit>(in, 3); @@ -123,25 +127,25 @@ void Skipjack::decrypt_n(const byte in[], byte out[], u32bit blocks) const u16bit W3 = load_le<u16bit>(in, 1); u16bit W4 = load_le<u16bit>(in, 0); - step_Bi(W2, W3, 32, FTAB); step_Bi(W3, W4, 31, FTAB); - step_Bi(W4, W1, 30, FTAB); step_Bi(W1, W2, 29, FTAB); - step_Bi(W2, W3, 28, FTAB); step_Bi(W3, W4, 27, FTAB); - step_Bi(W4, W1, 26, FTAB); step_Bi(W1, W2, 25, FTAB); - - step_Ai(W1, W2, 24, FTAB); step_Ai(W2, W3, 23, FTAB); - step_Ai(W3, W4, 22, FTAB); step_Ai(W4, W1, 21, FTAB); - step_Ai(W1, W2, 20, FTAB); step_Ai(W2, W3, 19, FTAB); - step_Ai(W3, W4, 18, FTAB); step_Ai(W4, W1, 17, FTAB); - - step_Bi(W2, W3, 16, FTAB); step_Bi(W3, W4, 15, FTAB); - step_Bi(W4, W1, 14, FTAB); step_Bi(W1, W2, 13, FTAB); - step_Bi(W2, W3, 12, FTAB); step_Bi(W3, W4, 11, FTAB); - step_Bi(W4, W1, 10, FTAB); step_Bi(W1, W2, 9, FTAB); - - step_Ai(W1, W2, 8, FTAB); step_Ai(W2, W3, 7, FTAB); - step_Ai(W3, W4, 6, FTAB); step_Ai(W4, W1, 5, FTAB); - step_Ai(W1, W2, 4, FTAB); step_Ai(W2, W3, 3, FTAB); - step_Ai(W3, W4, 2, FTAB); step_Ai(W4, W1, 1, FTAB); + step_Bi(W2, W3, 32, ftab); step_Bi(W3, W4, 31, ftab); + step_Bi(W4, W1, 30, ftab); step_Bi(W1, W2, 29, ftab); + step_Bi(W2, W3, 28, ftab); step_Bi(W3, W4, 27, ftab); + step_Bi(W4, W1, 26, ftab); step_Bi(W1, W2, 25, ftab); + + step_Ai(W1, W2, 24, ftab); step_Ai(W2, W3, 23, ftab); + step_Ai(W3, W4, 22, ftab); step_Ai(W4, W1, 21, ftab); + step_Ai(W1, W2, 20, ftab); step_Ai(W2, W3, 19, ftab); + step_Ai(W3, W4, 18, ftab); step_Ai(W4, W1, 17, ftab); + + step_Bi(W2, W3, 16, ftab); step_Bi(W3, W4, 15, ftab); + step_Bi(W4, W1, 14, ftab); step_Bi(W1, W2, 13, ftab); + step_Bi(W2, W3, 12, ftab); step_Bi(W3, W4, 11, ftab); + step_Bi(W4, W1, 10, ftab); step_Bi(W1, W2, 9, ftab); + + step_Ai(W1, W2, 8, ftab); step_Ai(W2, W3, 7, ftab); + step_Ai(W3, W4, 6, ftab); step_Ai(W4, W1, 5, ftab); + step_Ai(W1, W2, 4, ftab); step_Ai(W2, W3, 3, ftab); + step_Ai(W3, W4, 2, ftab); step_Ai(W4, W1, 1, ftab); store_le(out, W4, W3, W2, W1); diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp index 375590af1..805695087 100644 --- a/src/block/twofish/twofish.cpp +++ b/src/block/twofish/twofish.cpp @@ -121,7 +121,7 @@ void Twofish::key_schedule(const byte key[], u32bit length) SecureVector<byte, 16> S; for(u32bit j = 0; j != length; ++j) - rs_mul(S + 4*(j/8), key[j], j); + rs_mul(&S[4*(j/8)], key[j], j); if(length == 16) { diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp index bb1a30374..03e9f628c 100644 --- a/src/block/xtea/xtea.cpp +++ b/src/block/xtea/xtea.cpp @@ -63,7 +63,7 @@ void XTEA::encrypt_n(const byte in[], byte out[], u32bit blocks) const { while(blocks >= 4) { - xtea_encrypt_4(in, out, this->EK); + xtea_encrypt_4(in, out, &(this->EK[0])); in += 4 * BLOCK_SIZE; out += 4 * BLOCK_SIZE; blocks -= 4; @@ -93,7 +93,7 @@ void XTEA::decrypt_n(const byte in[], byte out[], u32bit blocks) const { while(blocks >= 4) { - xtea_decrypt_4(in, out, this->EK); + xtea_decrypt_4(in, out, &(this->EK[0])); in += 4 * BLOCK_SIZE; out += 4 * BLOCK_SIZE; blocks -= 4; diff --git a/src/filters/algo_filt.cpp b/src/filters/algo_filt.cpp index 51bf92380..88550d764 100644 --- a/src/filters/algo_filt.cpp +++ b/src/filters/algo_filt.cpp @@ -69,7 +69,7 @@ void StreamCipher_Filter::write(const byte input[], u32bit length) while(length) { u32bit copied = std::min(length, buffer.size()); - cipher->cipher(input, buffer, copied); + cipher->cipher(input, &buffer[0], copied); send(buffer, copied); input += copied; length -= copied; diff --git a/src/filters/filter.h b/src/filters/filter.h index a0b2e1c7a..81641db3d 100644 --- a/src/filters/filter.h +++ b/src/filters/filter.h @@ -66,6 +66,15 @@ class BOTAN_DLL Filter * @param in some input for the filter */ void send(const MemoryRegion<byte>& in) { send(&in[0], in.size()); } + + /** + * @param in some input for the filter + */ + void send(const MemoryRegion<byte>& in, u32bit length) + { + send(&in[0], length); + } + Filter(); private: Filter(const Filter&) {} diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index 535c22976..e88af0d87 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -98,10 +98,10 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, { ++seed; hash->update(seed); - hash->final(V + HASH_SIZE * (n-k)); + hash->final(&V[HASH_SIZE * (n-k)]); } - X.binary_decode(V + (HASH_SIZE - 1 - b/8), + X.binary_decode(&V[HASH_SIZE - 1 - b/8], V.size() - (HASH_SIZE - 1 - b/8)); X.set_bit(pbits-1); @@ -125,7 +125,7 @@ SecureVector<byte> generate_dsa_primes(RandomNumberGenerator& rng, while(true) { - rng.randomize(seed, seed.size()); + rng.randomize(&seed[0], seed.size()); if(generate_dsa_primes(rng, af, p, q, pbits, qbits, seed)) return seed; diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp index b565d7a21..7e6b2c811 100644 --- a/src/math/numbertheory/powm_mnt.cpp +++ b/src/math/numbertheory/powm_mnt.cpp @@ -52,7 +52,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) SecureVector<word> workspace(z.size()); g[0] = (base >= modulus) ? (base % modulus) : base; - bigint_mul(&z[0], z.size(), workspace, + bigint_mul(&z[0], z.size(), &workspace[0], g[0].data(), g[0].size(), g[0].sig_words(), R2.data(), R2.size(), R2.sig_words()); @@ -67,7 +67,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) const u32bit y_sig = y.sig_words(); zeroise(z); - bigint_mul(&z[0], z.size(), workspace, + bigint_mul(&z[0], z.size(), &workspace[0], x.data(), x.size(), x_sig, y.data(), y.size(), y_sig); @@ -91,7 +91,7 @@ BigInt Montgomery_Exponentiator::execute() const for(u32bit k = 0; k != window_bits; ++k) { zeroise(z); - bigint_sqr(&z[0], z.size(), workspace, + bigint_sqr(&z[0], z.size(), &workspace[0], x.data(), x.size(), x.sig_words()); montgomery_reduce(x, z, modulus, mod_words, mod_prime); @@ -103,7 +103,7 @@ BigInt Montgomery_Exponentiator::execute() const const BigInt& y = g[nibble-1]; zeroise(z); - bigint_mul(&z[0], z.size(), workspace, + bigint_mul(&z[0], z.size(), &workspace[0], x.data(), x.size(), x.sig_words(), y.data(), y.size(), y.sig_words()); diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp index 7eefa5923..a3917b3d7 100644 --- a/src/pubkey/dsa/dsa.cpp +++ b/src/pubkey/dsa/dsa.cpp @@ -94,8 +94,8 @@ DSA_Signature_Operation::sign(const byte msg[], u32bit msg_len, } SecureVector<byte> output(2*q.bytes()); - r.binary_encode(output + (output.size() / 2 - r.bytes())); - s.binary_encode(output + (output.size() - s.bytes())); + r.binary_encode(&output[output.size() / 2 - r.bytes()]); + s.binary_encode(&output[output.size() - s.bytes()]); return output; } diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index 8915a598e..88ef8a38a 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -55,8 +55,8 @@ ECDSA_Signature_Operation::sign(const byte msg[], u32bit msg_len, BigInt s = mod_order.multiply(inverse_mod(k, order), mul_add(x, r, m)); SecureVector<byte> output(2*order.bytes()); - r.binary_encode(output + (output.size() / 2 - r.bytes())); - s.binary_encode(output + (output.size() - s.bytes())); + r.binary_encode(&output[output.size() / 2 - r.bytes()]); + s.binary_encode(&output[output.size() - s.bytes()]); return output; } diff --git a/src/pubkey/pubkey.h b/src/pubkey/pubkey.h index ff4355675..2ea60fc86 100644 --- a/src/pubkey/pubkey.h +++ b/src/pubkey/pubkey.h @@ -230,7 +230,8 @@ class BOTAN_DLL PK_Verifier bool verify_message(const MemoryRegion<byte>& msg, const MemoryRegion<byte>& sig) { - return verify_message(msg, msg.size(), sig, sig.size()); + return verify_message(&msg[0], msg.size(), + &sig[0], sig.size()); } /** diff --git a/src/utils/buf_comp/buf_comp.h b/src/utils/buf_comp/buf_comp.h index e807e6abf..3afa086b0 100644 --- a/src/utils/buf_comp/buf_comp.h +++ b/src/utils/buf_comp/buf_comp.h @@ -37,7 +37,10 @@ class BOTAN_DLL BufferedComputation * Add new input to process. * @param in the input to process as a MemoryRegion */ - void update(const MemoryRegion<byte>& in) { add_data(in, in.size()); } + void update(const MemoryRegion<byte>& in) + { + add_data(&in[0], in.size()); + } /** * Add new input to process. @@ -72,7 +75,7 @@ class BOTAN_DLL BufferedComputation SecureVector<byte> final() { SecureVector<byte> output(OUTPUT_LENGTH); - final_result(output); + final_result(&output[0]); return output; } @@ -97,7 +100,7 @@ class BOTAN_DLL BufferedComputation */ SecureVector<byte> process(const MemoryRegion<byte>& in) { - add_data(in, in.size()); + add_data(&in[0], in.size()); return final(); } |