From 454f2dabbda3267d8e8a92de8ed442546c2adcd9 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 8 Apr 2015 16:18:16 -0400 Subject: [PATCH] EdDSA signature type added --- Identity.cpp | 17 +++++++++++++++-- Identity.h | 1 + Signature.cpp | 7 ++++++- Signature.h | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index fa8eabde..43decec1 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -94,7 +94,14 @@ namespace data excessBuf = new uint8_t[excessLen]; memcpy (excessBuf, signingKey + 128, excessLen); break; - } + } + case SIGNING_KEY_TYPE_EDDSA_SHA512: + { + size_t padding = 128 - i2p::crypto::EDDSA_PUBLIC_KEY_LENGTH; // 96 = 128 - 32 + i2p::context.GetRandomNumberGenerator ().GenerateBlock (m_StandardIdentity.signingKey, padding); + memcpy (m_StandardIdentity.signingKey + padding, signingKey, i2p::crypto::EDDSA_PUBLIC_KEY_LENGTH); + break; + } default: LogPrint ("Signing key type ", (int)type, " is not supported"); } @@ -344,7 +351,13 @@ namespace data memcpy (signingKey + 128, m_ExtendedBuffer + 4, excessLen); // right after signing and crypto key types m_Verifier = new i2p::crypto:: RSASHA5124096Verifier (signingKey); break; - } + } + case SIGNING_KEY_TYPE_EDDSA_SHA512: + { + size_t padding = 128 - i2p::crypto::EDDSA_PUBLIC_KEY_LENGTH; // 96 = 128 - 32 + m_Verifier = new i2p::crypto::EDDSAVerifier (m_StandardIdentity.signingKey + padding); + break; + } default: LogPrint ("Signing key type ", (int)keyType, " is not supported"); } diff --git a/Identity.h b/Identity.h index 16c9423e..beaf910e 100644 --- a/Identity.h +++ b/Identity.h @@ -117,6 +117,7 @@ namespace data const uint16_t SIGNING_KEY_TYPE_RSA_SHA256_2048 = 4; const uint16_t SIGNING_KEY_TYPE_RSA_SHA384_3072 = 5; const uint16_t SIGNING_KEY_TYPE_RSA_SHA512_4096 = 6; + const uint16_t SIGNING_KEY_TYPE_EDDSA_SHA512 = 7; typedef uint16_t SigningKeyType; typedef uint16_t CryptoKeyType; diff --git a/Signature.cpp b/Signature.cpp index ac3c35ea..f29a18be 100644 --- a/Signature.cpp +++ b/Signature.cpp @@ -77,7 +77,12 @@ namespace crypto private: CryptoPP::Integer q, l, d, I; - }; + }; + + bool EDDSAVerifier::Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const + { + return true; // TODO: + } } } diff --git a/Signature.h b/Signature.h index 23840562..24032708 100644 --- a/Signature.h +++ b/Signature.h @@ -410,6 +410,24 @@ namespace crypto { } }; + + // EdDSA + const size_t EDDSA_PUBLIC_KEY_LENGTH = 32; + const size_t EDDSA_SIGNATURE_LENGTH = 64; + const size_t EDDSA_PRIVATE_KEY_LENGTH = 32; + class EDDSAVerifier: public Verifier + { + public: + + EDDSAVerifier (const uint8_t * signingKey) + { + } + + bool Verify (const uint8_t * buf, size_t len, const uint8_t * signature) const; + + size_t GetPublicKeyLen () const { return EDDSA_PUBLIC_KEY_LENGTH; }; + size_t GetSignatureLen () const { return EDDSA_SIGNATURE_LENGTH; }; + }; } }