forked from lukem512/schnorr-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchnorr.h
More file actions
76 lines (55 loc) · 2.16 KB
/
Schnorr.h
File metadata and controls
76 lines (55 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _Schnorr
#define _Schnorr
#include <string>
#include <iostream>
using namespace std;
#include "cryptopp/osrng.h" // Random Number Generator
#include "cryptopp/eccrypto.h" // Elliptic Curve
#include "cryptopp/ecp.h" // F(p) EC
#include "cryptopp/integer.h" // Integer Operations
#include "cryptopp/ecp.h" // Curve Operations
using namespace CryptoPP;
NAMESPACE_BEGIN(SchnorrCPP)
// A class encapsulating the secp256r1 curve
// and Schnorr signing functions
class CCurve {
private:
static const size_t SCHNORR_SECRET_KEY_SIZE = 32;
static const size_t SCHNORR_SIG_SIZE = 32;
static const size_t SCHNORR_PUBLIC_KEY_COMPRESSED_SIZE = 33;
static const size_t SCHNORR_PUBLIC_KEY_UNCOMPRESSED_SIZE = 65;
bool secretKeySet;
bool publicKeySet;
ECP ec;
ECPPoint G;
Integer q;
AutoSeededRandomPool rng;
Integer secretKey;
ECPPoint Q; // public key
Integer HashPointMessage(const ECPPoint& R, const byte* message, int mlen);
void PrintInteger(Integer i);
public:
CCurve();
~CCurve();
bool HasPrivateKey();
bool HasPublicKey();
bool GenerateSecretKey();
bool GeneratePublicKey();
bool GenerateKeys();
bool SetVchPublicKey(std::vector<unsigned char> vchPubKey);
bool GetVchPublicKey(std::vector<unsigned char>& vchPubKey);
bool GetVchUncompressedPublicKey(std::vector<unsigned char>& vchPubKey);
bool SetVchSecretKey(std::vector<unsigned char> vchSecret);
bool GetVchSecretKey(std::vector<unsigned char>& vchSecret);
bool GetSignatureFromVch(std::vector<unsigned char> vchSig, Integer& sigE, Integer& sigS);
bool GetVchFromSignature(std::vector<unsigned char>& vchSig, Integer sigE, Integer sigS);
Integer GetPublicKeyX();
Integer GetPublicKeyY();
Integer GetSecretKey();
void ModuloAddToHex(Integer k, Integer iL, std::vector<unsigned char>& dataBytes);
void GetVchPointMultiplyAdd(Integer iL, std::vector<unsigned char>& dataBytes);
bool Sign(std::vector<unsigned char> vchHash, std::vector<unsigned char>& vchSig);
bool Verify(std::vector<unsigned char> vchHash, std::vector<unsigned char> vchSig);
};
NAMESPACE_END
#endif