csidh: Implements cSIDH torturer
This commit is contained in:
parent
1a54c2f55e
commit
029ec00936
@ -32,7 +32,7 @@ all: $(CODE_OBJ)
|
||||
$(CC) -o $(BUILD_DIR)/test test/main.c -L$(BUILD_DIR) -lcsidh
|
||||
|
||||
run: all
|
||||
GOPATH=$(GOPATH) go run test/test.go
|
||||
GOPATH=$(GOPATH) go run test/torturer.go
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
@ -13,7 +13,7 @@ static void u512_print(u512 const *x)
|
||||
|
||||
static void int_print(const int8_t v[37]) {
|
||||
for (size_t i = 0; i<37; i++)
|
||||
printf("0x%x,", (unsigned char)v[i]);
|
||||
printf("0x%X,", (unsigned char)v[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -24,6 +24,13 @@ static void fp_print(fp const *x)
|
||||
u512_print(&y);
|
||||
}
|
||||
|
||||
static void fp_print_n(fp const *x) {
|
||||
for (size_t i=0; i<8; i++) {
|
||||
printf("0x%016lX, ", x->x.c[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void fp_cmp(fp const *x, uint64_t const *org)
|
||||
{
|
||||
u512 y;
|
||||
@ -54,19 +61,58 @@ static void testLoopRef() {
|
||||
}
|
||||
}
|
||||
|
||||
static void testHardcoded() {
|
||||
private_key prv;
|
||||
public_key pub;
|
||||
uint8_t prv_bytes[] = {0xdb,0x54,0xe4,0xd4,0xd0,0xbd,0xee,0xcb,0xf4,0xd0,0xc2,0xbc,0x52,0x44,0x11,0xee,0xe1,0x14,0xd2,0x24,0xe5,0x0,0xcc,0xf5,0xc0,0xe1,0x1e,0xb3,0x43,0x52,0x45,0xbe,0xfb,0x54,0xc0,0x55,0xb2};
|
||||
uint64_t pub_bytes[] = {0x6BCAAD7EFD426976,0x743D780A06D2CDC5,0x841A2D76984849F7,0x1523EB45B3B78D5F,0xCF7A093C773EDF8D,0xFAB0FF04A7B4A54D,0x05DE322C864069D2,0x0C55DC69711DF47A};
|
||||
void print_bytes(uint8_t *out, size_t sz) {
|
||||
for(size_t i=0; i<sz; i++) {
|
||||
printf("%02X", out[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
memcpy(prv.e, prv_bytes, sizeof(prv.e));
|
||||
static void testHardcoded() {
|
||||
private_key prv1, prv2;
|
||||
public_key pub1, pub2;
|
||||
public_key shA;
|
||||
|
||||
uint8_t prv_bytes1[] = {0xaa, 0x54, 0xe4, 0xd4, 0xd0, 0xbd, 0xee, 0xcb, 0xf4, 0xd0, 0xc2, 0xbc, 0x52, 0x44, 0x11, 0xee, 0xe1, 0x14, 0xd2, 0x24, 0xe5, 0x0, 0xcc, 0xf5, 0xc0, 0xe1, 0x1e, 0xb3, 0x43, 0x52, 0x45, 0xbe, 0xfb, 0x54, 0xc0, 0x55, 0xb2};
|
||||
uint8_t prv_bytes2[] = {0xbb, 0x54, 0xe4, 0xd4, 0xd0, 0xbd, 0xee, 0xcb, 0xf4, 0xd0, 0xc2, 0xbc, 0x52, 0x44, 0x11, 0xee, 0xe1, 0x14, 0xd2, 0x24, 0xe5, 0x0, 0xcc, 0xf5, 0xc0, 0xe1, 0x1e, 0xb3, 0x43, 0x52, 0x45, 0xbe, 0xfb, 0x54, 0xc0, 0x55, 0xb2};
|
||||
memcpy(prv1.e, prv_bytes1, sizeof(prv1.e));
|
||||
memcpy(prv2.e, prv_bytes2, sizeof(prv2.e));
|
||||
// generate public key from private and compare to reference value
|
||||
csidh(&pub, &base, &prv);
|
||||
fp_cmp(&pub.A, pub_bytes);
|
||||
csidh(&pub1, &base, &prv1);
|
||||
csidh(&pub2, &base, &prv2);
|
||||
csidh(&shA, &pub2, &prv1);
|
||||
|
||||
uint8_t out[64];
|
||||
export_public(out, &pub1);
|
||||
print_bytes(out, sizeof(out));
|
||||
|
||||
export_public(out, &pub2);
|
||||
print_bytes(out, sizeof(out));
|
||||
|
||||
export_public(out, &shA);
|
||||
print_bytes(out, sizeof(out));
|
||||
}
|
||||
|
||||
static void testImportExport() {
|
||||
uint8_t buf_pub[64]={0};
|
||||
private_key prv1 = {0};
|
||||
private_key prv2 = {0};
|
||||
public_key pub1 = {0};
|
||||
public_key pub2 = {0};
|
||||
|
||||
csidh_private(&prv1);
|
||||
csidh_private(&prv2);
|
||||
|
||||
csidh(&pub1, &base, &prv1);
|
||||
|
||||
export_public(buf_pub, &pub1);
|
||||
import_public(&pub2, buf_pub);
|
||||
fp_print_n(&pub1.A);
|
||||
fp_print_n(&pub2.A);
|
||||
}
|
||||
|
||||
int main() {
|
||||
testImportExport();
|
||||
testHardcoded();
|
||||
testLoopRef();
|
||||
//testLoopRef();
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../ref/csidh
|
||||
#cgo LDFLAGS: -L../build -lcsidh
|
||||
#include <csidh.h>
|
||||
*/
|
||||
import "C"
|
||||
import "fmt"
|
||||
//import rand "crypto/rand"
|
||||
import csidh "github.com/henrydcase/nobs/dh/csidh"
|
||||
//import "unsafe"
|
||||
//import "runtime"
|
||||
import rand "crypto/rand"
|
||||
|
||||
func main() {
|
||||
prA := csidh.NewPrivateKey()
|
||||
prA.Generate(rand.Reader)
|
||||
|
||||
prB := csidh.NewPrivateKey()
|
||||
prB.Generate(rand.Reader)
|
||||
|
||||
for i:=0; i<7; i++ {
|
||||
var b [37]byte
|
||||
prA.Generate(rand.Reader)
|
||||
if !prA.Export(b[:]) {
|
||||
panic("Export failed")
|
||||
}
|
||||
fmt.Printf("%X\n", b)
|
||||
}
|
||||
|
||||
pkA := csidh.NewPublicKey()
|
||||
pkA.Generate(&prA)
|
||||
|
||||
/*
|
||||
print("ONE")
|
||||
pkB := csidh.NewPublicKey()
|
||||
pkB.Generate(&prB)
|
||||
print("ONE")
|
||||
pkA.DeriveSecret(&pkB, &prA)
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user