aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-03 13:18:54 +0000
committerlloyd <[email protected]>2010-09-03 13:18:54 +0000
commit449c9b9467c3e8dc08015094100162aea209623e (patch)
treecef38093356e6418b46640b43505f861db139ffe /checks
parent466548a644640fc73b24c8a4185a317f780a698f (diff)
Use the standalone version of the hex decoder instead of the wrapper that
previously existed in misc.cpp that emulated it via a pipe and filter.
Diffstat (limited to 'checks')
-rw-r--r--checks/bench.cpp1
-rw-r--r--checks/common.h6
-rw-r--r--checks/dolook.cpp8
-rw-r--r--checks/ec_tests.cpp108
-rw-r--r--checks/ecdsa.cpp16
-rw-r--r--checks/misc.cpp27
-rw-r--r--checks/pk.cpp55
-rw-r--r--checks/validate.cpp3
8 files changed, 102 insertions, 122 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp
index 8d35ac1c4..4e39bdf70 100644
--- a/checks/bench.cpp
+++ b/checks/bench.cpp
@@ -15,6 +15,7 @@
#include <botan/parsing.h>
#include <botan/symkey.h>
#include <botan/time.h>
+#include <botan/hex.h>
#include "common.h"
#include "bench.h"
diff --git a/checks/common.h b/checks/common.h
index 1b1e89bbf..493e2fc74 100644
--- a/checks/common.h
+++ b/checks/common.h
@@ -11,6 +11,7 @@
#include <botan/secmem.h>
#include <botan/filter.h>
#include <botan/rng.h>
+#include <botan/hex.h>
using Botan::byte;
using Botan::u32bit;
@@ -21,9 +22,6 @@ void strip_newlines(std::string& line);
void strip(std::string& line);
std::vector<std::string> parse(const std::string& line);
-std::string hex_encode(const byte in[], u32bit len);
-Botan::SecureVector<byte> decode_hex(const std::string&);
-
Botan::Filter* lookup(const std::string& algname,
const std::vector<std::string>& params);
@@ -75,7 +73,7 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
}
Fixed_Output_RNG(const std::string& in_str)
{
- Botan::SecureVector<byte> in = decode_hex(in_str);
+ Botan::SecureVector<byte> in = Botan::hex_decode(in_str);
buf.insert(buf.end(), in.begin(), in.begin() + in.size());
}
diff --git a/checks/dolook.cpp b/checks/dolook.cpp
index 71bb65725..92f7381c2 100644
--- a/checks/dolook.cpp
+++ b/checks/dolook.cpp
@@ -175,19 +175,19 @@ Filter* lookup_rng(const std::string& algname,
#if defined(BOTAN_HAS_DES)
if(algname == "X9.31-RNG(TripleDES)")
prng = new ANSI_X931_RNG(new TripleDES,
- new Fixed_Output_RNG(decode_hex(key)));
+ new Fixed_Output_RNG(hex_decode(key)));
#endif
#if defined(BOTAN_HAS_AES)
if(algname == "X9.31-RNG(AES-128)")
prng = new ANSI_X931_RNG(new AES_128,
- new Fixed_Output_RNG(decode_hex(key)));
+ new Fixed_Output_RNG(hex_decode(key)));
else if(algname == "X9.31-RNG(AES-192)")
prng = new ANSI_X931_RNG(new AES_192,
- new Fixed_Output_RNG(decode_hex(key)));
+ new Fixed_Output_RNG(hex_decode(key)));
else if(algname == "X9.31-RNG(AES-256)")
prng = new ANSI_X931_RNG(new AES_256,
- new Fixed_Output_RNG(decode_hex(key)));
+ new Fixed_Output_RNG(hex_decode(key)));
#endif
#endif
diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp
index 9362aa371..39ca1ded5 100644
--- a/checks/ec_tests.cpp
+++ b/checks/ec_tests.cpp
@@ -71,10 +71,10 @@ void test_point_turn_on_sp_red_mul()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex(p_secp);
- SecureVector<byte> sv_a_secp = decode_hex(a_secp);
- SecureVector<byte> sv_b_secp = decode_hex(b_secp);
- SecureVector<byte> sv_G_secp_comp = decode_hex(G_secp_comp);
+ SecureVector<byte> sv_p_secp = hex_decode(p_secp);
+ SecureVector<byte> sv_a_secp = hex_decode(a_secp);
+ SecureVector<byte> sv_b_secp = hex_decode(b_secp);
+ SecureVector<byte> sv_G_secp_comp = hex_decode(G_secp_comp);
BigInt bi_p_secp = BigInt::decode(sv_p_secp.begin(), sv_p_secp.size());
BigInt bi_a_secp = BigInt::decode(sv_a_secp.begin(), sv_a_secp.size());
BigInt bi_b_secp = BigInt::decode(sv_b_secp.begin(), sv_b_secp.size());
@@ -134,10 +134,10 @@ void test_coordinates()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -191,7 +191,7 @@ void test_point_mult ()
const CurveGFp& curve = secp160r1.get_curve();
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_G_secp_comp = decode_hex(G_secp_comp);
+ SecureVector<byte> sv_G_secp_comp = hex_decode(G_secp_comp);
PointGFp p_G = OS2ECP(sv_G_secp_comp, curve);
BigInt d_U("0xaa374ffc3ce144e6b073307972cb6d57b2a4e982");
@@ -210,10 +210,10 @@ void test_point_negative()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() );
@@ -237,7 +237,7 @@ void test_zeropoint()
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp("0xffffffffffffffffffffffffffffffff7fffffff");
BigInt bi_a_secp("0xffffffffffffffffffffffffffffffff7ffffffc");
BigInt bi_b_secp("0x1c97befc54bd7a8b65acf89f81d4d4adc565fa45");
@@ -286,7 +286,7 @@ void test_calc_with_zeropoint()
std::cout << "." << std::flush;
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp("0xffffffffffffffffffffffffffffffff7fffffff");
BigInt bi_a_secp("0xffffffffffffffffffffffffffffffff7ffffffc");
BigInt bi_b_secp("0x1c97befc54bd7a8b65acf89f81d4d4adc565fa45");
@@ -322,10 +322,10 @@ void test_add_point()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() );
@@ -358,10 +358,10 @@ void test_sub_point()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() );
@@ -393,10 +393,10 @@ void test_mult_point()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() );
@@ -422,10 +422,10 @@ void test_basic_operations()
std::string a_secp = "ffffffffffffffffffffffffffffffff7ffffffc";
std::string b_secp = "1c97befc54bd7a8b65acf89f81d4d4adc565fa45";
std::string G_secp_comp = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
BigInt bi_b_secp = BigInt::decode ( sv_b_secp.begin(), sv_b_secp.size() );
@@ -485,10 +485,10 @@ void test_enc_dec_compressed_160()
std::string G_secp_comp = "024A96B5688EF573284664698968C38BB913CBFC82";
std::string G_order_secp_comp = "0100000000000000000001F4C8F927AED3CA752257";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -514,10 +514,10 @@ void test_enc_dec_compressed_256()
std::string G_secp_comp = "036B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296";
std::string G_order_secp_comp = "ffffffff00000000ffffffffffffffffBCE6FAADA7179E84F3B9CAC2FC632551";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -545,10 +545,10 @@ void test_enc_dec_uncompressed_112()
std::string G_secp_uncomp = "044BA30AB5E892B4E1649DD0928643ADCD46F5882E3747DEF36E956E97";
std::string G_order_secp_uncomp = "36DF0AAFD8B8D7597CA10520D04B";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_uncomp = decode_hex ( G_secp_uncomp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -574,10 +574,10 @@ void test_enc_dec_uncompressed_521()
std::string G_secp_uncomp = "0400C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2ffA8DE3348B3C1856A429BF97E7E31C2E5BD66011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650";
std::string G_order_secp_uncomp = "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_uncomp = decode_hex ( G_secp_uncomp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -606,10 +606,10 @@ void test_enc_dec_uncompressed_521_prime_too_large()
std::string G_secp_uncomp = "0400C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2ffA8DE3348B3C1856A429BF97E7E31C2E5BD66011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650";
std::string G_order_secp_uncomp = "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409";
- SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_uncomp = decode_hex ( G_secp_uncomp );
+ SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_uncomp = hex_decode ( G_secp_uncomp );
BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_a_secp = BigInt::decode ( sv_a_secp.begin(), sv_a_secp.size() );
@@ -647,7 +647,7 @@ void test_gfp_store_restore()
std::string storrage = hex_encode(sv_mes, sv_mes.size());
// restore point (from std::string)
- SecureVector<byte> sv_new_point = decode_hex(storrage);
+ SecureVector<byte> sv_new_point = hex_decode(storrage);
PointGFp new_p = OS2ECP(sv_new_point, dom_pars.get_curve());
CHECK_MESSAGE( p == new_p, "original and restored point are different!");
@@ -661,7 +661,7 @@ void test_cdc_curve_33()
std::string G_secp_uncomp = "04081523d03d4f12cd02879dea4bf6a4f3a7df26ed888f10c5b2235a1274c386a2f218300dee6ed217841164533bcdc903f07a096f9fbf4ee95bac098a111f296f5830fe5c35b3e344d5df3a2256985f64fbe6d0edcc4c61d18bef681dd399df3d0194c5a4315e012e0245ecea56365baa9e8be1f7";
- SecureVector<byte> sv_G_uncomp = decode_hex ( G_secp_uncomp );
+ SecureVector<byte> sv_G_uncomp = hex_decode ( G_secp_uncomp );
BigInt bi_p_secp = BigInt("2117607112719756483104013348936480976596328609518055062007450442679169492999007105354629105748524349829824407773719892437896937279095106809");
BigInt bi_a_secp("0xa377dede6b523333d36c78e9b0eaa3bf48ce93041f6d4fc34014d08f6833807498deedd4290101c5866e8dfb589485d13357b9e78c2d7fbe9fe");
@@ -688,7 +688,7 @@ void test_more_zeropoint()
// by Falko
std::string G = "024a96b5688ef573284664698968c38bb913cbfc82";
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G );
BigInt bi_p("0xffffffffffffffffffffffffffffffff7fffffff");
BigInt bi_a("0xffffffffffffffffffffffffffffffff7ffffffc");
BigInt bi_b("0x1c97befc54bd7a8b65acf89f81d4d4adc565fa45");
diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp
index 3d2ee37f3..e3fde803d 100644
--- a/checks/ecdsa.cpp
+++ b/checks/ecdsa.cpp
@@ -164,7 +164,7 @@ void test_sign_then_ver(RandomNumberGenerator& rng)
PK_Signer signer(ecdsa, "EMSA1(SHA-1)");
- SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12");
+ SecureVector<byte> msg = hex_decode("12345678901234567890abcdef12");
SecureVector<byte> sig = signer.sign_message(msg, rng);
PK_Verifier verifier(ecdsa, "EMSA1(SHA-1)");
@@ -289,11 +289,11 @@ void test_create_and_verify(RandomNumberGenerator& rng)
std::string G_secp_comp = "04081523d03d4f12cd02879dea4bf6a4f3a7df26ed888f10c5b2235a1274c386a2f218300dee6ed217841164533bcdc903f07a096f9fbf4ee95bac098a111f296f5830fe5c35b3e344d5df3a2256985f64fbe6d0edcc4c61d18bef681dd399df3d0194c5a4315e012e0245ecea56365baa9e8be1f7";
std::string order_g = "0e1a16196e6000000000bc7f1618d867b15bb86474418f";
- // ::SecureVector<byte> sv_p_secp = decode_hex ( p_secp );
- SecureVector<byte> sv_a_secp = decode_hex ( a_secp );
- SecureVector<byte> sv_b_secp = decode_hex ( b_secp );
- SecureVector<byte> sv_G_secp_comp = decode_hex ( G_secp_comp );
- SecureVector<byte> sv_order_g = decode_hex ( order_g );
+ // ::SecureVector<byte> sv_p_secp = hex_decode ( p_secp );
+ SecureVector<byte> sv_a_secp = hex_decode ( a_secp );
+ SecureVector<byte> sv_b_secp = hex_decode ( b_secp );
+ SecureVector<byte> sv_G_secp_comp = hex_decode ( G_secp_comp );
+ SecureVector<byte> sv_order_g = hex_decode ( order_g );
// BigInt bi_p_secp = BigInt::decode ( sv_p_secp.begin(), sv_p_secp.size() );
BigInt bi_p_secp("2117607112719756483104013348936480976596328609518055062007450442679169492999007105354629105748524349829824407773719892437896937279095106809");
@@ -365,7 +365,7 @@ void test_curve_registry(RandomNumberGenerator& rng)
PK_Signer signer(ecdsa, "EMSA1(SHA-1)");
PK_Verifier verifier(ecdsa, "EMSA1(SHA-1)");
- SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12");
+ SecureVector<byte> msg = hex_decode("12345678901234567890abcdef12");
SecureVector<byte> sig = signer.sign_message(msg, rng);
if(!verifier.verify_message(msg, sig))
@@ -383,7 +383,7 @@ void test_read_pkcs8(RandomNumberGenerator& rng)
{
std::cout << "." << std::flush;
- SecureVector<byte> msg = decode_hex("12345678901234567890abcdef12");
+ SecureVector<byte> msg = hex_decode("12345678901234567890abcdef12");
try
{
diff --git a/checks/misc.cpp b/checks/misc.cpp
index ff95ed10f..31bc60435 100644
--- a/checks/misc.cpp
+++ b/checks/misc.cpp
@@ -8,10 +8,6 @@
#include <vector>
#include <string>
-#include <botan/pipe.h>
-#include <botan/hex.h>
-using namespace Botan;
-
#include "common.h"
void strip_comments(std::string& line)
@@ -40,29 +36,6 @@ void strip(std::string& line)
line = line.erase(line.find('\t'), 1);
}
-SecureVector<byte> decode_hex(const std::string& in)
- {
- SecureVector<byte> result;
-
- try {
- Botan::Pipe pipe(new Botan::Hex_Decoder);
- pipe.process_msg(in);
- result = pipe.read_all();
- }
- catch(std::exception)
- {
- result.destroy();
- }
- return result;
- }
-
-std::string hex_encode(const byte in[], u32bit len)
- {
- Botan::Pipe pipe(new Botan::Hex_Encoder);
- pipe.process_msg(in, len);
- return pipe.read_all_as_string();
- }
-
std::vector<std::string> parse(const std::string& line)
{
const char DELIMITER = ':';
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 23ceda7fe..0d06e0983 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -64,10 +64,19 @@ using namespace Botan;
namespace {
-BigInt to_bigint(const std::string& h)
+BigInt to_bigint(std::string input)
{
- return BigInt::decode(reinterpret_cast<const byte*>(h.data()),
- h.length(), BigInt::Hexadecimal);
+ while(input.find(' ') != std::string::npos)
+ input = input.erase(input.find(' '), 1);
+
+ while(input.find('\t') != std::string::npos)
+ input = input.erase(input.find('\t'), 1);
+
+ while(input.find('\n') != std::string::npos)
+ input = input.erase(input.find('\n'), 1);
+
+ return BigInt::decode(reinterpret_cast<const byte*>(input.data()),
+ input.length(), BigInt::Hexadecimal);
}
void dump_data(const SecureVector<byte>& out,
@@ -145,9 +154,9 @@ void validate_encryption(PK_Encryptor& e, PK_Decryptor& d,
const std::string& random, const std::string& exp,
bool& failure)
{
- SecureVector<byte> message = decode_hex(input);
- SecureVector<byte> expected = decode_hex(exp);
- Fixed_Output_RNG rng(decode_hex(random));
+ SecureVector<byte> message = hex_decode(input);
+ SecureVector<byte> expected = hex_decode(exp);
+ Fixed_Output_RNG rng(hex_decode(random));
SecureVector<byte> out = e.encrypt(message, rng);
if(out != expected)
@@ -165,9 +174,9 @@ void validate_signature(PK_Verifier& v, PK_Signer& s, const std::string& algo,
RandomNumberGenerator& rng,
const std::string& exp, bool& failure)
{
- SecureVector<byte> message = decode_hex(input);
+ SecureVector<byte> message = hex_decode(input);
- SecureVector<byte> expected = decode_hex(exp);
+ SecureVector<byte> expected = hex_decode(exp);
SecureVector<byte> sig = s.sign_message(message, message.size(), rng);
@@ -199,7 +208,7 @@ void validate_signature(PK_Verifier& v, PK_Signer& s, const std::string& algo,
const std::string& random,
const std::string& exp, bool& failure)
{
- Fixed_Output_RNG rng(decode_hex(random));
+ Fixed_Output_RNG rng(hex_decode(random));
validate_signature(v, s, algo, input, rng, exp, failure);
}
@@ -208,7 +217,7 @@ void validate_kas(PK_Key_Agreement& kas, const std::string& algo,
const SecureVector<byte>& pubkey, const std::string& output,
u32bit keylen, bool& failure)
{
- SecureVector<byte> expected = decode_hex(output);
+ SecureVector<byte> expected = hex_decode(output);
SecureVector<byte> got = kas.derive_key(keylen,
pubkey, pubkey.size()).bits_of();
@@ -310,8 +319,8 @@ u32bit validate_elg_enc(const std::string& algo,
validate_encryption(e, d, algo, str[4], str[5], str[6], failure);
}
else
- validate_decryption(d, algo, decode_hex(str[5]),
- decode_hex(str[4]), failure);
+ validate_decryption(d, algo, hex_decode(str[5]),
+ hex_decode(str[4]), failure);
return (failure ? 1 : 0);
#endif
@@ -358,8 +367,8 @@ u32bit validate_rsa_ver(const std::string& algo,
PK_Verifier v(key, emsa);
- SecureVector<byte> msg = decode_hex(str[2]);
- SecureVector<byte> sig = decode_hex(str[3]);
+ SecureVector<byte> msg = hex_decode(str[2]);
+ SecureVector<byte> sig = hex_decode(str[3]);
bool passed = true;
passed = v.verify_message(msg, msg.size(), sig, sig.size());
@@ -390,8 +399,8 @@ u32bit validate_rsa_ver_x509(const std::string& algo,
PK_Verifier v(*rsakey, emsa);
- SecureVector<byte> msg = decode_hex(str[1]);
- SecureVector<byte> sig = decode_hex(str[2]);
+ SecureVector<byte> msg = hex_decode(str[1]);
+ SecureVector<byte> sig = hex_decode(str[2]);
bool passed = v.verify_message(msg, msg.size(), sig, sig.size());
return (passed ? 0 : 1);
@@ -414,8 +423,8 @@ u32bit validate_rw_ver(const std::string& algo,
PK_Verifier v(key, emsa);
- SecureVector<byte> msg = decode_hex(str[2]);
- SecureVector<byte> sig = decode_hex(str[3]);
+ SecureVector<byte> msg = hex_decode(str[2]);
+ SecureVector<byte> sig = hex_decode(str[3]);
bool passed = true;
passed = v.verify_message(msg, msg.size(), sig, sig.size());
@@ -522,7 +531,7 @@ u32bit validate_gost_ver(const std::string& algo,
EC_Domain_Params group(OIDS::lookup(str[0]));
- PointGFp public_point = OS2ECP(decode_hex(str[1]), group.get_curve());
+ PointGFp public_point = OS2ECP(hex_decode(str[1]), group.get_curve());
GOST_3410_PublicKey gost(group, public_point);
@@ -530,8 +539,8 @@ u32bit validate_gost_ver(const std::string& algo,
PK_Verifier v(gost, emsa);
- SecureVector<byte> msg = decode_hex(str[2]);
- SecureVector<byte> sig = decode_hex(str[3]);
+ SecureVector<byte> msg = hex_decode(str[2]);
+ SecureVector<byte> sig = hex_decode(str[3]);
bool passed = v.verify_message(msg, msg.size(), sig, sig.size());
return (passed ? 0 : 1);
@@ -562,8 +571,8 @@ u32bit validate_dsa_ver(const std::string& algo,
PK_Verifier v(*dsakey, emsa);
- SecureVector<byte> msg = decode_hex(str[1]);
- SecureVector<byte> sig = decode_hex(str[2]);
+ SecureVector<byte> msg = hex_decode(str[1]);
+ SecureVector<byte> sig = hex_decode(str[2]);
v.set_input_format(DER_SEQUENCE);
bool passed = v.verify_message(msg, msg.size(), sig, sig.size());
diff --git a/checks/validate.cpp b/checks/validate.cpp
index 6e7a2e553..e1d5117a5 100644
--- a/checks/validate.cpp
+++ b/checks/validate.cpp
@@ -96,7 +96,6 @@ bool failed_test(const std::string&, std::vector<std::string>, bool, bool,
std::vector<std::string> parse(const std::string&);
void strip(std::string&);
-Botan::SecureVector<byte> decode_hex(const std::string&);
u32bit do_validation_tests(const std::string& filename,
RandomNumberGenerator& rng,
@@ -300,7 +299,7 @@ bool failed_test(const std::string& algo,
pipe.append(test);
pipe.append(new Botan::Hex_Encoder);
- Botan::SecureVector<byte> data = decode_hex(in);
+ Botan::SecureVector<byte> data = Botan::hex_decode(in);
const byte* data_ptr = data;
// this can help catch errors with buffering, etc