mirror of https://github.com/wolfSSL/wolfssl
Added new ECC API `wc_ecc_rs_raw_to_sig` to take raw unsigned R and S and encodes them into ECDSA signature format.
This commit is contained in:
parent
72f390a102
commit
9ccf876a21
|
@ -5580,6 +5580,48 @@ int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert ECC R,S raw unsigned bin to signature
|
||||||
|
r R component of signature
|
||||||
|
rSz R size
|
||||||
|
s S component of signature
|
||||||
|
sSz S size
|
||||||
|
out DER-encoded ECDSA signature
|
||||||
|
outlen [in/out] output buffer size, output signature size
|
||||||
|
return MP_OKAY on success
|
||||||
|
*/
|
||||||
|
int wc_ecc_rs_raw_to_sig(const byte* r, word32 rSz, const byte* s, word32 sSz,
|
||||||
|
byte* out, word32* outlen)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
mp_int rtmp;
|
||||||
|
mp_int stmp;
|
||||||
|
|
||||||
|
if (r == NULL || s == NULL || out == NULL || outlen == NULL)
|
||||||
|
return ECC_BAD_ARG_E;
|
||||||
|
|
||||||
|
err = mp_init_multi(&rtmp, &stmp, NULL, NULL, NULL, NULL);
|
||||||
|
if (err != MP_OKAY)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err = mp_read_unsigned_bin(&rtmp, r, rSz);
|
||||||
|
if (err == MP_OKAY)
|
||||||
|
err = mp_read_unsigned_bin(&stmp, s, sSz);
|
||||||
|
|
||||||
|
/* convert mp_ints to ECDSA sig, initializes rtmp and stmp internally */
|
||||||
|
if (err == MP_OKAY)
|
||||||
|
err = StoreECC_DSA_Sig(out, outlen, &rtmp, &stmp);
|
||||||
|
|
||||||
|
if (err == MP_OKAY) {
|
||||||
|
if (mp_iszero(&rtmp) == MP_YES || mp_iszero(&stmp) == MP_YES)
|
||||||
|
err = MP_ZERO_E;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_clear(&rtmp);
|
||||||
|
mp_clear(&stmp);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert ECC signature to R,S
|
Convert ECC signature to R,S
|
||||||
|
|
|
@ -487,6 +487,9 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
|
int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
|
int wc_ecc_rs_raw_to_sig(const byte* r, word32 rSz, const byte* s, word32 sSz,
|
||||||
|
byte* out, word32* outlen);
|
||||||
|
WOLFSSL_API
|
||||||
int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
|
int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
|
||||||
byte* s, word32* sLen);
|
byte* s, word32* sLen);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
|
|
Loading…
Reference in New Issue