-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathEc.h
78 lines (65 loc) · 1.58 KB
/
Ec.h
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
77
78
// This file is a part of RCKangaroo software
// (c) 2024, RetiredCoder (RC)
// License: GPLv3, see "LICENSE.TXT" file
// https://github.com/RetiredC/Kang-2
#pragma once
#include "defs.h"
#include "utils.h"
class EcInt
{
public:
EcInt();
void Assign(EcInt& val);
void Set(u64 val);
void SetZero();
bool SetHexStr(const char* str);
void GetHexStr(char* str);
u16 GetU16(int index);
bool Add(EcInt& val); //returns true if carry
bool Sub(EcInt& val); //returns true if carry
void Neg();
void Neg256();
void ShiftRight(int nbits);
void ShiftLeft(int nbits);
bool IsLessThanU(EcInt& val);
bool IsLessThanI(EcInt& val);
bool IsEqual(EcInt& val);
bool IsZero();
void Mul_u64(EcInt& val, u64 multiplier);
void Mul_i64(EcInt& val, i64 multiplier);
void AddModP(EcInt& val);
void SubModP(EcInt& val);
void NegModP();
void NegModN();
void MulModP(EcInt& val);
void InvModP();
void SqrtModP();
void RndBits(int nbits);
void RndMax(EcInt& max);
u64 data[4 + 1];
};
class EcPoint
{
public:
bool IsEqual(EcPoint& pnt);
void LoadFromBuffer64(u8* buffer);
void SaveToBuffer64(u8* buffer);
bool SetHexStr(const char* str);
EcInt x;
EcInt y;
};
class Ec
{
public:
static EcPoint AddPoints(EcPoint& pnt1, EcPoint& pnt2);
static EcPoint DoublePoint(EcPoint& pnt);
static EcPoint MultiplyG(EcInt& k);
#ifdef DEBUG_MODE
static EcPoint MultiplyG_Fast(EcInt& k);
#endif
static EcInt CalcY(EcInt& x, bool is_even);
static bool IsValidPoint(EcPoint& pnt);
};
void InitEc();
void DeInitEc();
void SetRndSeed(u64 seed);