chore: update deps

This commit is contained in:
Rim
2025-02-20 06:23:40 -05:00
parent de69a8a5ec
commit 8c7893f668
1045 changed files with 27193 additions and 13903 deletions

View File

@ -53,7 +53,7 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
#endif /* LTC_RSA_BLINDING */
NULL)) != CRYPT_OK)
{ return err; }
if ((err = mp_read_unsigned_bin(tmp, (unsigned char *)in, (int)inlen)) != CRYPT_OK)
if ((err = mp_read_unsigned_bin(tmp, in, (int)inlen)) != CRYPT_OK)
{ goto error; }
@ -130,7 +130,7 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
#ifdef LTC_RSA_CRT_HARDENING
if (has_crt_parameters) {
if ((err = mp_exptmod(tmp, key->e, key->N, tmpa)) != CRYPT_OK) { goto error; }
if ((err = mp_read_unsigned_bin(tmpb, (unsigned char *)in, (int)inlen)) != CRYPT_OK) { goto error; }
if ((err = mp_read_unsigned_bin(tmpb, in, (int)inlen)) != CRYPT_OK) { goto error; }
if (mp_cmp(tmpa, tmpb) != LTC_MP_EQ) { err = CRYPT_ERROR; goto error; }
}
#endif

View File

@ -9,107 +9,61 @@
#ifdef LTC_MRSA
/* Public-Key Cryptography Standards (PKCS) #8:
* Private-Key Information Syntax Specification Version 1.2
* https://tools.ietf.org/html/rfc5208
*
* PrivateKeyInfo ::= SEQUENCE {
* version Version,
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
* privateKey PrivateKey,
* attributes [0] IMPLICIT Attributes OPTIONAL }
* where:
* - Version ::= INTEGER
* - PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
* - PrivateKey ::= OCTET STRING
* - Attributes ::= SET OF Attribute
*
* EncryptedPrivateKeyInfo ::= SEQUENCE {
* encryptionAlgorithm EncryptionAlgorithmIdentifier,
* encryptedData EncryptedData }
* where:
* - EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
* - EncryptedData ::= OCTET STRING
*/
int rsa_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, rsa_key *key)
{
int err;
LTC_ARGCHK(key != NULL);
LTC_UNUSED_PARAM(alg_id);
if ((err = rsa_init(key)) != CRYPT_OK) {
return err;
}
if ((err = rsa_import_pkcs1(priv_key->data, priv_key->size, key)) != CRYPT_OK) {
rsa_free(key);
return err;
}
key->type = PK_PRIVATE;
return err;
}
/**
Import an RSAPrivateKey in PKCS#8 format
@param in The packet to import from
@param inlen It's length (octets)
@param passwd The password for decrypting privkey
@param passwdlen Password's length (octets)
@param pw_ctx The password context when decrypting the private key
@param key [out] Destination for newly imported key
@return CRYPT_OK if successful, upon error allocated memory is freed
*/
int rsa_import_pkcs8(const unsigned char *in, unsigned long inlen,
const void *passwd, unsigned long passwdlen,
const password_ctx *pw_ctx,
rsa_key *key)
{
int err;
unsigned char *buf1 = NULL, *buf2 = NULL;
unsigned long buf1len, buf2len;
unsigned long oid[16], version;
const char *rsaoid;
ltc_asn1_list alg_seq[2], top_seq[3];
ltc_asn1_list *l = NULL;
unsigned char *decrypted = NULL;
unsigned long decryptedlen;
ltc_asn1_list *alg_id, *priv_key;
enum ltc_oid_id pka;
LTC_ARGCHK(in != NULL);
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(ltc_mp.name != NULL);
LTC_ARGCHK(in != NULL);
/* get RSA alg oid */
err = pk_get_oid(LTC_OID_RSA, &rsaoid);
if (err != CRYPT_OK) { goto LBL_NOFREE; }
/* alloc buffers */
buf1len = inlen; /* approx. */
buf1 = XMALLOC(buf1len);
if (buf1 == NULL) { err = CRYPT_MEM; goto LBL_NOFREE; }
buf2len = inlen; /* approx. */
buf2 = XMALLOC(buf2len);
if (buf2 == NULL) { err = CRYPT_MEM; goto LBL_FREE1; }
/* init key */
if ((err = rsa_init(key)) != CRYPT_OK) { goto LBL_FREE2; }
/* try to decode encrypted priv key */
if ((err = pkcs8_decode_flexi(in, inlen, passwd, passwdlen, &l)) != CRYPT_OK) {
goto LBL_ERR;
if ((err = pkcs8_decode_flexi(in, inlen, pw_ctx, &l)) != CRYPT_OK) {
return err;
}
decrypted = l->data;
decryptedlen = l->size;
/* try to decode unencrypted priv key */
LTC_SET_ASN1(alg_seq, 0, LTC_ASN1_OBJECT_IDENTIFIER, oid, 16UL);
LTC_SET_ASN1(alg_seq, 1, LTC_ASN1_NULL, NULL, 0UL);
LTC_SET_ASN1(top_seq, 0, LTC_ASN1_SHORT_INTEGER, &version, 1UL);
LTC_SET_ASN1(top_seq, 1, LTC_ASN1_SEQUENCE, alg_seq, 2UL);
LTC_SET_ASN1(top_seq, 2, LTC_ASN1_OCTET_STRING, buf1, buf1len);
err=der_decode_sequence(decrypted, decryptedlen, top_seq, 3UL);
if (err != CRYPT_OK) { goto LBL_ERR; }
/* check alg oid */
if ((err = pk_oid_cmp_with_asn1(rsaoid, &alg_seq[0])) != CRYPT_OK) {
goto LBL_ERR;
if ((err = pkcs8_get_children(l, &pka, &alg_id, &priv_key)) != CRYPT_OK) {
goto LBL_DER_FREE;
}
if (pka != LTC_OID_RSA) {
err = CRYPT_INVALID_PACKET;
goto LBL_DER_FREE;
}
if ((err = rsa_import_pkcs1(buf1, top_seq[2].size, key)) != CRYPT_OK) {
goto LBL_ERR;
}
key->type = PK_PRIVATE;
err = CRYPT_OK;
goto LBL_FREE2;
err = rsa_import_pkcs8_asn1(alg_id, priv_key, key);
LBL_ERR:
rsa_free(key);
LBL_FREE2:
if (l) der_free_sequence_flexi(l);
XFREE(buf2);
LBL_FREE1:
XFREE(buf1);
LBL_NOFREE:
LBL_DER_FREE:
der_free_sequence_flexi(l);
return err;
}

View File

@ -39,8 +39,8 @@ int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key)
}
if ((err = x509_decode_public_key_from_certificate(in, inlen,
LTC_OID_RSA, LTC_ASN1_NULL,
NULL, NULL,
LTC_OID_RSA,
LTC_ASN1_NULL, NULL, NULL,
(public_key_decode_cb)s_rsa_decode, key)) != CRYPT_OK) {
rsa_free(key);
} else {

View File

@ -9,8 +9,6 @@
*/
#ifdef LTC_MRSA
#include <stdarg.h>
static void s_mpi_shrink_multi(void **a, ...)
{
void **cur;
@ -81,7 +79,7 @@ void rsa_shrink_key(rsa_key *key)
/**
Init an RSA key
@param key The RSA key to free
@param key The RSA key to initialize
@return CRYPT_OK if successful
*/
int rsa_init(rsa_key *key)

View File

@ -130,7 +130,7 @@ int rsa_make_key_ubin_e(prng_state *prng, int wprng, int size,
return err;
}
if ((err = mp_read_unsigned_bin(tmp_e, (unsigned char *)e, elen)) == CRYPT_OK)
if ((err = mp_read_unsigned_bin(tmp_e, e, elen)) == CRYPT_OK)
err = rsa_make_key_bn_e(prng, wprng, size, tmp_e, key);
mp_clear(tmp_e);

View File

@ -31,10 +31,10 @@ int rsa_set_key(const unsigned char *N, unsigned long Nlen,
if ((err = rsa_init(key)) != CRYPT_OK) return err;
if ((err = mp_read_unsigned_bin(key->N , (unsigned char *)N , Nlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->e , (unsigned char *)e , elen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->N , N , Nlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->e , e , elen)) != CRYPT_OK) { goto LBL_ERR; }
if (d && dlen) {
if ((err = mp_read_unsigned_bin(key->d , (unsigned char *)d , dlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->d , d , dlen)) != CRYPT_OK) { goto LBL_ERR; }
key->type = PK_PRIVATE;
}
else {
@ -72,8 +72,8 @@ int rsa_set_factors(const unsigned char *p, unsigned long plen,
if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH;
if ((err = mp_read_unsigned_bin(key->p , (unsigned char *)p , plen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->q , (unsigned char *)q , qlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->p , p , plen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->q , q , qlen)) != CRYPT_OK) { goto LBL_ERR; }
return CRYPT_OK;
LBL_ERR:
@ -110,9 +110,9 @@ int rsa_set_crt_params(const unsigned char *dP, unsigned long dPlen,
if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH;
if ((err = mp_read_unsigned_bin(key->dP, (unsigned char *)dP, dPlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->dQ, (unsigned char *)dQ, dQlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->qP, (unsigned char *)qP, qPlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->dP, dP, dPlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->dQ, dQ, dQlen)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = mp_read_unsigned_bin(key->qP, qP, qPlen)) != CRYPT_OK) { goto LBL_ERR; }
return CRYPT_OK;
LBL_ERR:

View File

@ -78,7 +78,8 @@ int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen,
}
} else {
/* PKCS #1 v1.5 pad the hash */
unsigned char *tmpin;
unsigned char *tmpin = NULL;
const unsigned char *tmpin_ro;
if (padding == LTC_PKCS_1_V1_5) {
ltc_asn1_list digestinfo[2], siginfo[2];
@ -111,14 +112,15 @@ int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen,
XFREE(tmpin);
return err;
}
tmpin_ro = tmpin;
} else {
/* set the pointer and data-length to the input values */
tmpin = (unsigned char *)in;
tmpin_ro = in;
y = inlen;
}
x = *outlen;
err = pkcs_1_v1_5_encode(tmpin, y, LTC_PKCS_1_EMSA, modulus_bitlen, NULL, 0, out, &x);
err = pkcs_1_v1_5_encode(tmpin_ro, y, LTC_PKCS_1_EMSA, modulus_bitlen, NULL, 0, out, &x);
if (padding == LTC_PKCS_1_V1_5) {
XFREE(tmpin);