yggm/libs/edsign.cuh

26 lines
898 B
Plaintext
Raw Normal View History

2025-03-13 19:43:54 +05:00
#pragma once
2025-03-13 04:09:27 +05:00
#include <ed25519.cuh>
#include <sha512.cuh>
#include <fprime.cuh>
2025-03-13 19:43:54 +05:00
__device__ __forceinline__ void expand_key(unsigned char* expanded, const unsigned char* secret) {
2025-03-13 04:09:27 +05:00
struct sha512_state s;
sha512_init(&s);
2025-03-13 19:43:54 +05:00
sha512_final(&s, secret, 32);
sha512_get(&s, expanded, 0, 64);
2025-03-13 04:09:27 +05:00
ed25519_prepare(expanded);
}
2025-03-13 19:43:54 +05:00
__device__ __forceinline__ void pp(unsigned char* packed, const struct ed25519_pt* p) {
unsigned char x[F25519_SIZE], y[F25519_SIZE];
2025-03-13 04:09:27 +05:00
ed25519_unproject(x, y, p);
ed25519_pack(packed, x, y);
}
2025-03-13 19:43:54 +05:00
__device__ __forceinline__ void sm_pack(unsigned char* r, const unsigned char* k) {
2025-03-13 04:09:27 +05:00
struct ed25519_pt p;
ed25519_smult(&p, &ed25519_base, k);
pp(r, &p);
}
2025-03-13 19:43:54 +05:00
__device__ __forceinline__ void edsign_sec_to_pub(unsigned char* pub, const unsigned char* secret) {
unsigned char expanded[64];
2025-03-13 04:09:27 +05:00
expand_key(expanded, secret);
sm_pack(pub, expanded);
2025-03-13 19:45:21 +05:00
}