Botan  1.11.15
src/lib/pubkey/curve25519/curve25519.h
Go to the documentation of this file.
00001 /*
00002 * Curve25519
00003 * (C) 2014 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_CURVE_25519_H__
00009 #define BOTAN_CURVE_25519_H__
00010 
00011 #include <botan/pk_keys.h>
00012 
00013 namespace Botan {
00014 
00015 class BOTAN_DLL Curve25519_PublicKey : public virtual Public_Key
00016    {
00017    public:
00018       std::string algo_name() const override { return "Curve25519"; }
00019 
00020       size_t estimated_strength() const override { return 128; }
00021 
00022       size_t max_input_bits() const { return 256; }
00023 
00024       bool check_key(RandomNumberGenerator& rng, bool strong) const override;
00025 
00026       AlgorithmIdentifier algorithm_identifier() const override;
00027 
00028       std::vector<byte> x509_subject_public_key() const override;
00029 
00030       std::vector<byte> public_value() const { return unlock(m_public); }
00031 
00032       Curve25519_PublicKey(const AlgorithmIdentifier& alg_id,
00033                            const secure_vector<byte>& key_bits);
00034 
00035       Curve25519_PublicKey(const secure_vector<byte>& pub) : m_public(pub) {}
00036    protected:
00037       Curve25519_PublicKey() {}
00038       secure_vector<byte> m_public;
00039    };
00040 
00041 class BOTAN_DLL Curve25519_PrivateKey : public Curve25519_PublicKey,
00042                                         public virtual Private_Key,
00043                                         public virtual PK_Key_Agreement_Key
00044    {
00045    public:
00046       Curve25519_PrivateKey(const AlgorithmIdentifier& alg_id,
00047                             const secure_vector<byte>& key_bits,
00048                             RandomNumberGenerator& rng);
00049 
00050       Curve25519_PrivateKey(RandomNumberGenerator& rng);
00051 
00052       Curve25519_PrivateKey(const secure_vector<byte>& secret_key);
00053 
00054       std::vector<byte> public_value() const override { return Curve25519_PublicKey::public_value(); }
00055 
00056       secure_vector<byte> agree(const byte w[], size_t w_len) const;
00057 
00058       const secure_vector<byte>& get_x() const { return m_private; }
00059 
00060       secure_vector<byte> pkcs8_private_key() const override;
00061 
00062       bool check_key(RandomNumberGenerator& rng, bool strong) const override;
00063    private:
00064       secure_vector<byte> m_private;
00065    };
00066 
00067 /*
00068 * The types above are just wrappers for curve25519_donna, plus defining
00069 * encodings for public and private keys.
00070 */
00071 int BOTAN_DLL curve25519_donna(uint8_t mypublic[32],
00072                                const uint8_t secret[32],
00073                                const uint8_t basepoint[32]);
00074 
00075 }
00076 
00077 #endif