aboutsummaryrefslogtreecommitdiffstats
path: root/src/prf_x942.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-19 00:07:25 +0000
committerlloyd <[email protected]>2006-05-19 00:07:25 +0000
commitf090e030be53e574fecbe7cf50edfb5fdacb53e1 (patch)
tree0bff0c249a9dbcb674fcd2491ab17e3d123ef1f9 /src/prf_x942.cpp
parenta0af7b26591f8fb79d1f06fe42548e1eb0c35e90 (diff)
Syntax changes to the BER and DER APIs to improve readability of code
that uses them. These changes are not backwards compatible, this commit updates all uses of the APIs within the library.
Diffstat (limited to 'src/prf_x942.cpp')
-rw-r--r--src/prf_x942.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/prf_x942.cpp b/src/prf_x942.cpp
index 59a0d96c6..508fe6cc9 100644
--- a/src/prf_x942.cpp
+++ b/src/prf_x942.cpp
@@ -20,13 +20,11 @@ namespace {
*************************************************/
MemoryVector<byte> encode_x942_int(u32bit n)
{
- byte n_buf[4];
+ byte n_buf[4] = { 0 };
for(u32bit j = 0; j != 4; ++j)
n_buf[j] = get_byte(j, n);
- DER_Encoder encoder;
- encoder.encode(n_buf, 4, OCTET_STRING);
- return encoder.get_contents();
+ return DER_Encoder().encode(n_buf, 4, OCTET_STRING).get_contents();
}
}
@@ -46,28 +44,30 @@ SecureVector<byte> X942_PRF::derive(u32bit key_len,
while(key.size() != key_len)
{
- DER_Encoder encoder;
-
- encoder.start_sequence()
- .start_sequence()
- .encode(kek_algo)
- .add_raw_octets(encode_x942_int(counter))
- .end_sequence();
-
- if(salt_len)
- {
- encoder.start_explicit(ASN1_Tag(0));
- encoder.encode(salt, salt_len, OCTET_STRING);
- encoder.end_explicit(ASN1_Tag(0));
- }
-
- encoder.start_explicit(ASN1_Tag(2))
- .add_raw_octets(encode_x942_int(8 * key_len))
- .end_explicit(ASN1_Tag(2))
- .end_sequence();
-
hash->update(secret, secret_len);
- hash->update(encoder.get_contents());
+
+ hash->update(
+ DER_Encoder().start_cons(SEQUENCE)
+
+ .start_cons(SEQUENCE)
+ .encode(kek_algo)
+ .raw_bytes(encode_x942_int(counter))
+ .end_cons()
+
+ .encode_if(salt_len != 0,
+ DER_Encoder()
+ .start_explicit(0)
+ .encode(salt, salt_len, OCTET_STRING)
+ .end_explicit()
+ )
+
+ .start_explicit(2)
+ .raw_bytes(encode_x942_int(8 * key_len))
+ .end_explicit()
+
+ .end_cons().get_contents()
+ );
+
SecureVector<byte> digest = hash->final();
key.append(digest, std::min(digest.size(), key_len - key.size()));