monotone

monotone Mtn Source Tree

Root/botan/emsa3.cpp

1/*************************************************
2* EMSA3 Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/emsa.h>
7#include <botan/hash_id.h>
8#include <botan/lookup.h>
9
10namespace Botan {
11
12/*************************************************
13* EMSA3 Update Operation *
14*************************************************/
15void EMSA3::update(const byte input[], u32bit length)
16 {
17 hash->update(input, length);
18 }
19
20/*************************************************
21* Return the raw (unencoded) data *
22*************************************************/
23SecureVector<byte> EMSA3::raw_data()
24 {
25 return hash->final();
26 }
27
28/*************************************************
29* EMSA3 Encode Operation *
30*************************************************/
31SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
32 u32bit output_bits)
33 {
34 if(msg.size() != hash->OUTPUT_LENGTH)
35 throw Encoding_Error("EMSA3::encoding_of: Bad input length");
36
37 u32bit output_length = output_bits / 8;
38 if(output_length < hash_id.size() + hash->OUTPUT_LENGTH + 10)
39 throw Encoding_Error("EMSA3::pad: Output length is too small");
40
41 SecureVector<byte> T(output_length);
42 const u32bit P_LENGTH = output_length - hash->OUTPUT_LENGTH -
43 hash_id.size() - 2;
44
45 T[0] = 0x01;
46 set_mem(T+1, P_LENGTH, 0xFF);
47 T[P_LENGTH+1] = 0x00;
48 T.copy(P_LENGTH+2, hash_id, hash_id.size());
49 T.copy(output_length-hash->OUTPUT_LENGTH, msg, msg.size());
50 return T;
51 }
52
53/*************************************************
54* EMSA3 Constructor *
55*************************************************/
56EMSA3::EMSA3(const std::string& hash_name)
57 {
58 hash_id = pkcs_hash_id(hash_name);
59 hash = get_hash(hash_name);
60 }
61
62}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status