Compare commits
22 Commits
Author | SHA1 | Date |
---|---|---|
tecnovert | ec7eb48a95 | 5 months ago |
tecnovert | 654be83506 | 1 year ago |
tecnovert | c5821d1402 | 1 year ago |
Ofek Lev | a3c2fdb643 | 2 years ago |
Ofek Lev | ed638bd850 | 2 years ago |
Ofek Lev | 0121668d05 | 2 years ago |
Ofek Lev | 1dd0675add | 2 years ago |
Ofek Lev | 063a313e4d | 2 years ago |
Ofek Lev | 367ee22857 | 2 years ago |
Antoine Poinsot | a7284cd4d6 | 2 years ago |
Antoine Poinsot | a57bd24702 | 2 years ago |
Antoine Poinsot | 8a2c89dc3c | 2 years ago |
Weiliang Li | f13612f377 | 2 years ago |
tecnovert | baa97e7a21 | 2 years ago |
tecnovert | d79f30b84e | 2 years ago |
tecnovert | 2c53babe78 | 2 years ago |
tecnovert | 4bb26b7b35 | 2 years ago |
tecnovert | 4374483b64 | 3 years ago |
tecnovert | 45ce99b6ab | 3 years ago |
tecnovert | 12e3621070 | 4 years ago |
tecnovert | 9fd55f7b32 | 4 years ago |
tecnovert | 92cce4287a | 4 years ago |
35 changed files with 1161 additions and 50 deletions
@ -0,0 +1,35 @@ |
|||
#!/bin/bash |
|||
|
|||
set -e -x |
|||
|
|||
build_dll() { |
|||
./autogen.sh |
|||
echo "LDFLAGS = -no-undefined" >> Makefile.am |
|||
./configure --host=$1 --enable-module-recovery --enable-experimental --enable-module-ecdh --enable-endomorphism --disable-jni --enable-module-ed25519 --enable-module-generator --enable-module-dleag --enable-module-ecdsaotves |
|||
make |
|||
} |
|||
|
|||
cd .. |
|||
#git clone https://github.com/bitcoin-core/secp256k1.git |
|||
#mv secp256k1 64bit |
|||
wget -O secp256k1_anonswap.zip https://github.com/tecnovert/secp256k1/archive/refs/tags/anonswap_v0.2.zip |
|||
unzip secp256k1_anonswap.zip |
|||
mv secp256k1-anonswap_v0.2 64bit |
|||
|
|||
cp 64bit 32bit -R |
|||
|
|||
cd 64bit |
|||
build_dll x86_64-w64-mingw32 |
|||
mv .libs/libsecp256k1-0.dll ../clean/coincurve/libsecp256k1.dll |
|||
cd ../clean |
|||
python setup.py bdist_wheel --universal --plat-name=win_amd64 |
|||
rm coincurve/libsecp256k1.dll |
|||
|
|||
cd ../32bit |
|||
build_dll i686-w64-mingw32 |
|||
mv .libs/libsecp256k1-0.dll ../clean/coincurve/libsecp256k1.dll |
|||
cd ../clean |
|||
python setup.py bdist_wheel --universal --plat-name=win32 |
|||
|
|||
mv dist/* ../coincurve/dist/ |
|||
cd ../coincurve |
@ -0,0 +1,34 @@ |
|||
FROM ubuntu:bionic as build |
|||
|
|||
# Install required system packages |
|||
RUN apt-get update && apt-get install -y \ |
|||
build-essential \ |
|||
mingw-w64 \ |
|||
autoconf \ |
|||
libtool \ |
|||
wget \ |
|||
unzip |
|||
|
|||
ARG UNAME=user |
|||
ARG UID=1000 |
|||
ARG GID=1000 |
|||
RUN groupadd -g $GID -o $UNAME |
|||
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME |
|||
|
|||
USER $UNAME |
|||
|
|||
WORKDIR /home/user |
|||
|
|||
RUN wget -O secp256k1_anonswap.zip https://github.com/tecnovert/secp256k1/archive/refs/tags/anonswap_v0.2.zip && \ |
|||
unzip secp256k1_anonswap.zip && \ |
|||
mv secp256k1-anonswap_v0.2 64bit |
|||
|
|||
RUN cd 64bit && \ |
|||
./autogen.sh && \ |
|||
echo "LDFLAGS = -no-undefined" >> Makefile.am && \ |
|||
./configure --host=x86_64-w64-mingw32 --enable-module-recovery --enable-experimental --enable-module-ecdh --enable-module-extrakeys --enable-module-schnorrsig --enable-benchmark=no --enable-tests=no --enable-openssl-tests=no --enable-exhaustive-tests=no --enable-static --disable-dependency-tracking --with-pic --enable-module-ed25519 --enable-module-generator --enable-module-dleag --enable-module-ecdsaotves && \ |
|||
make && \ |
|||
mv .libs/libsecp256k1-0.dll . |
|||
|
|||
FROM scratch as artifact |
|||
COPY --from=build /home/user/64bit/libsecp256k1-0.dll /coincurve/libsecp256k1.dll |
@ -0,0 +1,51 @@ |
|||
|
|||
size_t secp256k1_dleag_size(size_t n_bits); |
|||
|
|||
int secp256k1_dleag_prove( |
|||
const secp256k1_context *ctx, |
|||
unsigned char *proof_out, |
|||
size_t *proof_len, /* Input length of proof_out buffer, output length of proof. */ |
|||
const unsigned char *key, /* 32 bytes */ |
|||
size_t n_bits, |
|||
const unsigned char *nonce, /* 32 bytes */ |
|||
const secp256k1_generator *gen_s_a, |
|||
const secp256k1_generator *gen_s_b, |
|||
const unsigned char *gen_e_a, |
|||
const unsigned char *gen_e_b |
|||
); |
|||
|
|||
int secp256k1_dleag_verify( |
|||
const secp256k1_context *ctx, |
|||
const unsigned char *proof, |
|||
size_t proof_len, |
|||
const secp256k1_generator *gen_s_a, |
|||
const secp256k1_generator *gen_s_b, |
|||
const unsigned char *gen_e_a, |
|||
const unsigned char *gen_e_b |
|||
); |
|||
|
|||
int secp256k1_dleag_verify_secp256k1_point( |
|||
const secp256k1_context *ctx, |
|||
const unsigned char *p |
|||
); |
|||
|
|||
int secp256k1_dleag_verify_ed25519_point( |
|||
const secp256k1_context *ctx, |
|||
const unsigned char *p |
|||
); |
|||
|
|||
|
|||
int secp256k1_ed25519_dleag_prove( |
|||
const secp256k1_context *ctx, |
|||
unsigned char *proof_out, |
|||
size_t *proof_len, /* Input length of proof_out buffer, output length of proof. */ |
|||
const unsigned char *key, /* 32 bytes */ |
|||
size_t n_bits, |
|||
const unsigned char *nonce /* 32 bytes */ |
|||
); |
|||
|
|||
int secp256k1_ed25519_dleag_verify( |
|||
const secp256k1_context *ctx, |
|||
const unsigned char *proof, |
|||
size_t proof_len |
|||
); |
@ -0,0 +1,32 @@ |
|||
int ecdsaotves_enc_sign( |
|||
const secp256k1_context *ctx, |
|||
unsigned char *ct_out, |
|||
const unsigned char *skS, |
|||
const unsigned char *pkE, |
|||
const unsigned char *msg32 |
|||
); |
|||
|
|||
int ecdsaotves_enc_verify( |
|||
const secp256k1_context *ctx, |
|||
const unsigned char *pkS, |
|||
const unsigned char *pkE, |
|||
const unsigned char *msg32, |
|||
const unsigned char *ct |
|||
); |
|||
|
|||
int ecdsaotves_dec_sig( |
|||
const secp256k1_context *ctx, |
|||
unsigned char *sig_out, |
|||
size_t *sig_length, |
|||
const unsigned char *skE, |
|||
const unsigned char *ct |
|||
); |
|||
|
|||
int ecdsaotves_rec_enc_key( |
|||
const secp256k1_context *ctx, |
|||
unsigned char *key_out, |
|||
const unsigned char *pkE, |
|||
const unsigned char *ct, |
|||
const unsigned char *dersig, |
|||
size_t sig_length |
|||
); |
@ -0,0 +1,19 @@ |
|||
extern const unsigned char ed25519_gen[32]; |
|||
extern const unsigned char ed25519_gen2[32]; |
|||
|
|||
int crypto_scalarmult_ed25519_base_noclamp( |
|||
unsigned char *q, |
|||
const unsigned char *n |
|||
); |
|||
|
|||
int crypto_core_ed25519_add( |
|||
unsigned char *r, |
|||
const unsigned char *p, |
|||
const unsigned char *q |
|||
); |
|||
|
|||
void crypto_core_ed25519_scalar_add( |
|||
unsigned char *z, |
|||
const unsigned char *x, |
|||
const unsigned char *y |
|||
); |
@ -0,0 +1,78 @@ |
|||
typedef struct { |
|||
unsigned char data[64]; |
|||
} secp256k1_xonly_pubkey; |
|||
|
|||
typedef struct { |
|||
unsigned char data[96]; |
|||
} secp256k1_keypair; |
|||
|
|||
int secp256k1_xonly_pubkey_parse( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_xonly_pubkey* pubkey, |
|||
const unsigned char *input32 |
|||
); |
|||
|
|||
int secp256k1_xonly_pubkey_serialize( |
|||
const secp256k1_context* ctx, |
|||
unsigned char *output32, |
|||
const secp256k1_xonly_pubkey* pubkey |
|||
); |
|||
|
|||
int secp256k1_xonly_pubkey_cmp( |
|||
const secp256k1_context* ctx, |
|||
const secp256k1_xonly_pubkey* pk1, |
|||
const secp256k1_xonly_pubkey* pk2 |
|||
); |
|||
|
|||
int secp256k1_xonly_pubkey_from_pubkey( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_xonly_pubkey *xonly_pubkey, |
|||
int *pk_parity, |
|||
const secp256k1_pubkey *pubkey |
|||
); |
|||
|
|||
int secp256k1_xonly_pubkey_tweak_add( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_pubkey *output_pubkey, |
|||
const secp256k1_xonly_pubkey *internal_pubkey, |
|||
const unsigned char *tweak32 |
|||
); |
|||
|
|||
int secp256k1_xonly_pubkey_tweak_add_check( |
|||
const secp256k1_context* ctx, |
|||
const unsigned char *tweaked_pubkey32, |
|||
int tweaked_pk_parity, |
|||
const secp256k1_xonly_pubkey *internal_pubkey, |
|||
const unsigned char *tweak32 |
|||
); |
|||
|
|||
int secp256k1_keypair_create( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_keypair *keypair, |
|||
const unsigned char *seckey |
|||
); |
|||
|
|||
int secp256k1_keypair_sec( |
|||
const secp256k1_context* ctx, |
|||
unsigned char *seckey, |
|||
const secp256k1_keypair *keypair |
|||
); |
|||
|
|||
int secp256k1_keypair_pub( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_pubkey *pubkey, |
|||
const secp256k1_keypair *keypair |
|||
); |
|||
|
|||
int secp256k1_keypair_xonly_pub( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_xonly_pubkey *pubkey, |
|||
int *pk_parity, |
|||
const secp256k1_keypair *keypair |
|||
); |
|||
|
|||
int secp256k1_keypair_xonly_tweak_add( |
|||
const secp256k1_context* ctx, |
|||
secp256k1_keypair *keypair, |
|||
const unsigned char *tweak32 |
|||
); |
@ -0,0 +1,7 @@ |
|||
typedef struct { |
|||
unsigned char data[64]; |
|||
} secp256k1_generator; |
|||
|
|||
extern const secp256k1_generator secp256k1_generator_const_g; |
|||
extern const secp256k1_generator secp256k1_generator_const_h; |
|||
|
@ -0,0 +1,51 @@ |
|||
typedef int (*secp256k1_nonce_function_hardened)( |
|||
unsigned char *nonce32, |
|||
const unsigned char *msg, |
|||
size_t msglen, |
|||
const unsigned char *key32, |
|||
const unsigned char *xonly_pk32, |
|||
const unsigned char *algo, |
|||
size_t algolen, |
|||
void *data |
|||
); |
|||
|
|||
extern const secp256k1_nonce_function_hardened secp256k1_nonce_function_bip340; |
|||
|
|||
typedef struct { |
|||
unsigned char magic[4]; |
|||
secp256k1_nonce_function_hardened noncefp; |
|||
void* ndata; |
|||
} secp256k1_schnorrsig_extraparams; |
|||
|
|||
int secp256k1_schnorrsig_sign( |
|||
const secp256k1_context* ctx, |
|||
unsigned char *sig64, |
|||
const unsigned char *msg32, |
|||
const secp256k1_keypair *keypair, |
|||
const unsigned char *aux_rand32 |
|||
); |
|||
|
|||
int secp256k1_schnorrsig_sign32( |
|||
const secp256k1_context* ctx, |
|||
unsigned char *sig64, |
|||
const unsigned char *msg32, |
|||
const secp256k1_keypair *keypair, |
|||
const unsigned char *aux_rand32 |
|||
); |
|||
|
|||
int secp256k1_schnorrsig_sign_custom( |
|||
const secp256k1_context* ctx, |
|||
unsigned char *sig64, |
|||
const unsigned char *msg, |
|||
size_t msglen, |
|||
const secp256k1_keypair *keypair, |
|||
secp256k1_schnorrsig_extraparams *extraparams |
|||
); |
|||
|
|||
int secp256k1_schnorrsig_verify( |
|||
const secp256k1_context* ctx, |
|||
const unsigned char *sig64, |
|||
const unsigned char *msg, |
|||
size_t msglen, |
|||
const secp256k1_xonly_pubkey *pubkey |
|||
); |
@ -1,3 +1,12 @@ |
|||
from coincurve.context import GLOBAL_CONTEXT, Context |
|||
from coincurve.keys import PrivateKey, PublicKey |
|||
from coincurve.keys import PrivateKey, PublicKey, PublicKeyXOnly |
|||
from coincurve.utils import verify_signature |
|||
|
|||
__all__ = [ |
|||
'GLOBAL_CONTEXT', |
|||
'Context', |
|||
'PrivateKey', |
|||
'PublicKey', |
|||
'PublicKeyXOnly', |
|||
'verify_signature', |
|||
] |
|||
|
@ -0,0 +1,82 @@ |
|||
from coincurve.context import GLOBAL_CONTEXT |
|||
from coincurve.flags import EC_COMPRESSED, EC_UNCOMPRESSED |
|||
from ._libsecp256k1 import ffi, lib |
|||
|
|||
|
|||
def dleag_proof_len(bits=252): |
|||
return lib.secp256k1_dleag_size(bits) |
|||
|
|||
|
|||
def get_nonce(): |
|||
try: |
|||
import secrets |
|||
|
|||
return secrets.token_bytes(32) |
|||
except Exception: |
|||
from os import urandom |
|||
|
|||
return urandom(32) |
|||
|
|||
|
|||
def dleag_prove(private_key, nonce_bytes=None, context=GLOBAL_CONTEXT): |
|||
proof_length = dleag_proof_len() |
|||
proof_output = ffi.new('unsigned char[{}]'.format(proof_length)) |
|||
|
|||
proof_length_p = ffi.new('size_t *') |
|||
proof_length_p[0] = proof_length |
|||
|
|||
# nonce_bytes = ffi.from_buffer(secrets.token_bytes(32)) |
|||
if nonce_bytes is None: |
|||
nonce_bytes = get_nonce() |
|||
rv = lib.secp256k1_ed25519_dleag_prove( |
|||
context.ctx, |
|||
proof_output, |
|||
proof_length_p, |
|||
private_key.secret, |
|||
252, |
|||
nonce_bytes, |
|||
) |
|||
|
|||
if rv != 1: |
|||
raise ValueError('secp256k1_ed25519_dleag_prove failed') |
|||
|
|||
# TODO: How to clear memory? Add random module to secp256k1? |
|||
# ffi.memmove(nonce_bytes, bytes([0] * 32), 32) |
|||
return bytes(ffi.buffer(proof_output, proof_length)) |
|||
|
|||
|
|||
def dleag_verify(proof, context=GLOBAL_CONTEXT): |
|||
proof_bytes = ffi.from_buffer(proof) |
|||
proof_length = len(proof) |
|||
|
|||
rv = lib.secp256k1_ed25519_dleag_verify( |
|||
context.ctx, |
|||
proof_bytes, |
|||
proof_length, |
|||
) |
|||
|
|||
return True if rv == 1 else False |
|||
|
|||
|
|||
def verify_secp256k1_point(pubkey_bytes, context=GLOBAL_CONTEXT): |
|||
if len(pubkey_bytes) != 33: |
|||
raise ValueError('Invalid pubkey length') |
|||
|
|||
rv = lib.secp256k1_dleag_verify_secp256k1_point( |
|||
context.ctx, |
|||
pubkey_bytes |
|||
) |
|||
|
|||
return True if rv == 1 else False |
|||
|
|||
|
|||
def verify_ed25519_point(pubkey_bytes, context=GLOBAL_CONTEXT): |
|||
if len(pubkey_bytes) != 32: |
|||
raise ValueError('Invalid pubkey length') |
|||
|
|||
rv = lib.secp256k1_dleag_verify_ed25519_point( |
|||
context.ctx, |
|||
pubkey_bytes |
|||
) |
|||
|
|||
return True if rv == 1 else False |
@ -0,0 +1,89 @@ |
|||
from coincurve.context import GLOBAL_CONTEXT |
|||
from coincurve.utils import bytes_to_int, int_to_bytes, sha256 |
|||
from ._libsecp256k1 import ffi, lib |
|||
|
|||
|
|||
def ecdsaotves_enc_sign(private_key_sign, public_key_encrypt, msg, context=GLOBAL_CONTEXT): |
|||
ct_length = 196 |
|||
ct_output = ffi.new('unsigned char[{}]'.format(ct_length)) |
|||
|
|||
if len(private_key_sign) != 32: |
|||
raise ValueError('private_key_sign must be 32 bytes') |
|||
if len(public_key_encrypt) != 33: |
|||
raise ValueError('public_key_encrypt must be 33 bytes') |
|||
if len(msg) != 32: |
|||
raise ValueError('msg must be 32 bytes') |
|||
|
|||
rv = lib.ecdsaotves_enc_sign( |
|||
context.ctx, |
|||
ct_output, |
|||
private_key_sign, |
|||
public_key_encrypt, |
|||
msg, |
|||
) |
|||
|
|||
if rv != 1: |
|||
raise ValueError('ecdsaotves_enc_sign failed') |
|||
|
|||
return bytes(ffi.buffer(ct_output, ct_length)) |
|||
|
|||
|
|||
def ecdsaotves_enc_verify(public_key_sign, public_key_encrypt, msg, ct, context=GLOBAL_CONTEXT): |
|||
if len(public_key_sign) != 33: |
|||
raise ValueError('public_key_sign must be 33 bytes') |
|||
if len(public_key_encrypt) != 33: |
|||
raise ValueError('public_key_encrypt must be 33 bytes') |
|||
if len(msg) != 32: |
|||
raise ValueError('msg must be 32 bytes') |
|||
if len(ct) != 196: |
|||
raise ValueError('ciphertext must be 196 bytes') |
|||
|
|||
rv = lib.ecdsaotves_enc_verify( |
|||
context.ctx, |
|||
public_key_sign, |
|||
public_key_encrypt, |
|||
msg, |
|||
ct, |
|||
) |
|||
|
|||
return True if rv == 1 else False |
|||
|
|||
|
|||
def ecdsaotves_dec_sig(private_key_encrypt, ct, context=GLOBAL_CONTEXT): |
|||
if len(private_key_encrypt) != 32: |
|||
raise ValueError('private_key_encrypt must be 32 bytes') |
|||
if len(ct) != 196: |
|||
raise ValueError('ciphertext must be 196 bytes') |
|||
|
|||
output_length = ffi.new('size_t *') |
|||
output_length[0] = 100 |
|||
sig_output = ffi.new('unsigned char[{}]'.format(100)) |
|||
|
|||
rv = lib.ecdsaotves_dec_sig( |
|||
context.ctx, |
|||
sig_output, |
|||
output_length, |
|||
private_key_encrypt, |
|||
ct, |
|||
) |
|||
if rv != 1: |
|||
raise ValueError('ecdsaotves_dec_sig failed') |
|||
|
|||
return bytes(ffi.buffer(sig_output, output_length[0])) |
|||
|
|||
|
|||
def ecdsaotves_rec_enc_key(public_key_encrypt, ct, sig_der, context=GLOBAL_CONTEXT): |
|||
|
|||
if len(public_key_encrypt) != 33: |
|||
raise ValueError('public_key_encrypt must be 33 bytes') |
|||
if len(ct) != 196: |
|||
raise ValueError('ciphertext must be 196 bytes') |
|||
|
|||
key_output = ffi.new('unsigned char[{}]'.format(32)) |
|||
|
|||
sig_length = len(sig_der) |
|||
rv = lib.ecdsaotves_rec_enc_key(context.ctx, key_output, public_key_encrypt, ct, sig_der, sig_length) |
|||
if rv != 1: |
|||
raise ValueError('ecdsaotves_rec_enc_key failed') |
|||
|
|||
return bytes(ffi.buffer(key_output, 32)) |
@ -0,0 +1,57 @@ |
|||
from asn1crypto.keys import ECDomainParameters, ECPointBitString, ECPrivateKey, PrivateKeyAlgorithm, PrivateKeyInfo |
|||
|
|||
from coincurve.context import GLOBAL_CONTEXT |
|||
from coincurve.ecdsa import cdata_to_der, der_to_cdata, deserialize_recoverable, recover, serialize_recoverable |
|||
from coincurve.flags import EC_COMPRESSED, EC_UNCOMPRESSED |
|||
from coincurve.utils import bytes_to_int, int_to_bytes_padded |
|||
from ._libsecp256k1 import ffi, lib |
|||
|
|||
|
|||
GROUP_ORDER_INT = 2 ** 252 + 27742317777372353535851937790883648493 |
|||
|
|||
|
|||
def get_valid_secret(): |
|||
try: |
|||
import secrets |
|||
|
|||
return int_to_bytes_padded(9 + secrets.randbelow(GROUP_ORDER_INT - 9)) |
|||
except Exception: |
|||
from os import urandom |
|||
|
|||
while True: |
|||
secret = urandom(32) |
|||
if 9 < bytes_to_int(secret) < GROUP_ORDER_INT: |
|||
return secret |
|||
|
|||
|
|||
def ed25519_get_pubkey(privkey): |
|||
pubkey_output = ffi.new('unsigned char[{}]'.format(32)) |
|||
privkey_le = privkey[::-1] |
|||
rv = lib.crypto_scalarmult_ed25519_base_noclamp(pubkey_output, privkey_le) |
|||
assert(rv == 0) |
|||
return bytes(ffi.buffer(pubkey_output, 32)) |
|||
|
|||
|
|||
def ed25519_scalar_add(x, y): |
|||
output = ffi.new('unsigned char[{}]'.format(32)) |
|||
x_le = x[::-1] |
|||
y_le = y[::-1] |
|||
lib.crypto_core_ed25519_scalar_add(output, x_le, y_le) |
|||
return bytes(ffi.buffer(output, 32))[::-1] |
|||
|
|||
|
|||
def ed25519_add(x, y): |
|||
output = ffi.new('unsigned char[{}]'.format(32)) |
|||
rv = lib.crypto_core_ed25519_add(output, x, y) |
|||
assert(rv == 0) |
|||
return bytes(ffi.buffer(output, 32)) |
|||
|
|||
|
|||
class Ed25519PrivateKey: |
|||
def __init__(self, secret=None, context=GLOBAL_CONTEXT): |
|||
self.context = context |
|||
|
|||
|
|||
class Ed25519PublicKey: |
|||
def __init__(self, data, context=GLOBAL_CONTEXT): |
|||
self.context = context |
@ -0,0 +1,12 @@ |
|||
from coincurve.dleag import dleag_prove, dleag_verify |
|||
from coincurve.ed25519 import get_valid_secret |
|||
from coincurve.keys import PrivateKey, PublicKey |
|||
|
|||
|
|||
class TestDLEAG: |
|||
def test_dleag(self): |
|||
secret = get_valid_secret() |
|||
private_key = PrivateKey(secret) |
|||
proof = dleag_prove(private_key) |
|||
|
|||
assert True == dleag_verify(proof) |
@ -0,0 +1,33 @@ |
|||
import sys |
|||
from coincurve.ecdsaotves import ecdsaotves_enc_sign, ecdsaotves_enc_verify, ecdsaotves_dec_sig, ecdsaotves_rec_enc_key |
|||
from coincurve.keys import PrivateKey, PublicKey |
|||
from coincurve.utils import get_valid_secret, sha256 |
|||
|
|||
|
|||
class TestECDSAOTVES: |
|||
def test_ecdsaotves(self): |
|||
secret_sign = get_valid_secret() |
|||
secret_encrypt = get_valid_secret() |
|||
|
|||
pk_sign = PublicKey.from_secret(secret_sign) |
|||
pk_encrypt = PublicKey.from_secret(secret_encrypt) |
|||
pk_sb = pk_sign.format() |
|||
pk_eb = pk_encrypt.format() |
|||
|
|||
message = 'otves message' |
|||
if sys.version_info[0] > 2: |
|||
message_hash = sha256(bytes(message, 'utf-8')) |
|||
else: |
|||
message_hash = sha256(message) |
|||
|
|||
ct = ecdsaotves_enc_sign(secret_sign, pk_eb, message_hash) |
|||
|
|||
assert ecdsaotves_enc_verify(pk_sb, pk_eb, message_hash, ct) |
|||
|
|||
sig = ecdsaotves_dec_sig(secret_encrypt, ct) |
|||
|
|||
assert pk_sign.verify(sig, message_hash, hasher=None) |
|||
|
|||
secret_rec = ecdsaotves_rec_enc_key(pk_eb, ct, sig) |
|||
|
|||
assert secret_rec == secret_encrypt |
Loading…
Reference in new issue