Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
RetiredC authored Dec 12, 2024
1 parent 75b1005 commit 6a2ee85
Show file tree
Hide file tree
Showing 14 changed files with 3,944 additions and 7 deletions.
748 changes: 748 additions & 0 deletions Ec.cpp

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions Ec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
Loading

0 comments on commit 6a2ee85

Please sign in to comment.