1 /**
2 * EMSA1 BSI Variant
3 *
4 * Copyright:
5 * (C) 1999-2008 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 * 2007 FlexSecure GmbH
8 *
9 * License:
10 * Botan is released under the Simplified BSD License (see LICENSE.md)
11 */
12 module botan.pk_pad.emsa1_bsi;
13
14 import botan.constants;
15 static if (BOTAN_HAS_EMSA1_BSI):
16 import botan.pk_pad.emsa1;
17 import botan.hash.hash;
18 import botan.utils.types;
19
20 /**
21 * EMSA1_BSI is a variant of EMSA1 specified by the BSI. It accepts
22 * only hash values which are less or equal than the maximum key
23 * length. The implementation comes from InSiTo
24 */
25 final class EMSA1BSI : EMSA1, EMSA
26 {
27 public:
28 /**
29 * Params:
30 * hash = the hash object to use
31 */
32 this(HashFunction hash)
33 {
34 super(hash);
35 }
36
37 /*
38 * EMSA1 BSI Encode Operation
39 */
40 override SecureVector!ubyte encodingOf(const ref SecureVector!ubyte msg,
41 size_t output_bits,
42 RandomNumberGenerator rng)
43 {
44 //logDebug("EMSA1BSI Encode");
45 if (msg.length != hashOutputLength())
46 throw new EncodingError("EMSA1_BSI::encodingOf: Invalid size for input");
47
48 if (8*msg.length <= output_bits)
49 return msg.dup;
50
51 throw new EncodingError("EMSA1_BSI::encodingOf: max key input size exceeded");
52 }
53
54 // Interface fallthrough
55 override SecureVector!ubyte rawData() { return super.rawData(); }
56 override bool verify(const ref SecureVector!ubyte coded,
57 const ref SecureVector!ubyte raw, size_t key_bits)
58 {
59 return super.verify(coded, raw, key_bits);
60 }
61 override void update(const(ubyte)* input, size_t length)
62 {
63 super.update(input, length);
64 }
65 }
66