1 /* 2 * (C) 2014,2015 Jack Lloyd 3 * 4 * Botan is released under the Simplified BSD License (see license.txt) 5 */ 6 7 #include "tests.h" 8 9 #if defined(BOTAN_HAS_GOST_34_10_2001) 10 #include <botan/gost_3410.h> 11 #include "test_pubkey.h" 12 #endif 13 14 namespace Botan_Tests { 15 16 namespace { 17 18 #if defined(BOTAN_HAS_GOST_34_10_2001) 19 20 class GOST_3410_2001_Verification_Tests final : public PK_Signature_Verification_Test 21 { 22 public: GOST_3410_2001_Verification_Tests()23 GOST_3410_2001_Verification_Tests() : PK_Signature_Verification_Test( 24 "GOST 34.10-2001", 25 "pubkey/gost_3410_verify.vec", 26 "P,A,B,Gx,Gy,Oid,Order,Cofactor,Px,Py,Hash,Msg,Signature") {} 27 load_public_key(const VarMap & vars)28 std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) override 29 { 30 const BigInt p = vars.get_req_bn("P"); 31 const BigInt a = vars.get_req_bn("A"); 32 const BigInt b = vars.get_req_bn("B"); 33 const BigInt Gx = vars.get_req_bn("Gx"); 34 const BigInt Gy = vars.get_req_bn("Gy"); 35 const BigInt order = vars.get_req_bn("Order"); 36 const BigInt cofactor = vars.get_req_bn("Cofactor"); 37 const Botan::OID oid(vars.get_req_str("Oid")); 38 39 Botan::EC_Group group(p, a, b, Gx, Gy, order, cofactor, oid); 40 41 const BigInt Px = vars.get_req_bn("Px"); 42 const BigInt Py = vars.get_req_bn("Py"); 43 44 const Botan::PointGFp public_point = group.point(Px, Py); 45 46 std::unique_ptr<Botan::Public_Key> key(new Botan::GOST_3410_PublicKey(group, public_point)); 47 return key; 48 } 49 default_padding(const VarMap & vars) const50 std::string default_padding(const VarMap& vars) const override 51 { 52 const std::string hash = vars.get_req_str("Hash"); 53 if(hash == "Raw") 54 return hash; 55 return "EMSA1(" + hash + ")"; 56 } 57 }; 58 59 class GOST_3410_2001_Signature_Tests final : public PK_Signature_Generation_Test 60 { 61 public: GOST_3410_2001_Signature_Tests()62 GOST_3410_2001_Signature_Tests() : PK_Signature_Generation_Test( 63 "GOST 34.10-2001", 64 "pubkey/gost_3410_sign.vec", 65 "P,A,B,Gx,Gy,Oid,Order,X,Cofactor,Hash,Nonce,Msg,Signature") {} 66 load_private_key(const VarMap & vars)67 std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) override 68 { 69 const BigInt p = vars.get_req_bn("P"); 70 const BigInt a = vars.get_req_bn("A"); 71 const BigInt b = vars.get_req_bn("B"); 72 const BigInt Gx = vars.get_req_bn("Gx"); 73 const BigInt Gy = vars.get_req_bn("Gy"); 74 const BigInt order = vars.get_req_bn("Order"); 75 const BigInt cofactor = vars.get_req_bn("Cofactor"); 76 const Botan::OID oid(vars.get_req_str("Oid")); 77 78 Botan::EC_Group group(p, a, b, Gx, Gy, order, cofactor, oid); 79 80 const BigInt x = vars.get_req_bn("X"); 81 82 std::unique_ptr<Botan::Private_Key> key(new Botan::GOST_3410_PrivateKey(Test::rng(), group, x)); 83 return key; 84 } 85 default_padding(const VarMap & vars) const86 std::string default_padding(const VarMap& vars) const override 87 { 88 const std::string hash = vars.get_req_str("Hash"); 89 if(hash == "Raw") 90 return hash; 91 return "EMSA1(" + hash + ")"; 92 } 93 test_rng(const std::vector<uint8_t> & nonce) const94 Botan::RandomNumberGenerator* test_rng(const std::vector<uint8_t>& nonce) const override 95 { 96 return new Fixed_Output_Position_RNG(nonce, 1); 97 } 98 }; 99 100 class GOST_3410_2001_Keygen_Tests final : public PK_Key_Generation_Test 101 { 102 public: keygen_params() const103 std::vector<std::string> keygen_params() const override 104 { 105 return { "gost_256A", "secp256r1" }; 106 } algo_name() const107 std::string algo_name() const override 108 { 109 return "GOST-34.10"; 110 } 111 }; 112 113 BOTAN_REGISTER_TEST("pubkey", "gost_3410_verify", GOST_3410_2001_Verification_Tests); 114 BOTAN_REGISTER_TEST("pubkey", "gost_3410_sign", GOST_3410_2001_Signature_Tests); 115 BOTAN_REGISTER_TEST("pubkey", "gost_3410_keygen", GOST_3410_2001_Keygen_Tests); 116 117 #endif 118 119 } 120 121 } 122