/** * Get all the RSA private key specifics from an ASN.1 encoded file */ int asn1_get_private_key(const uint8_t *buf, int len, RSA_CTX **rsa_ctx) { int offset = 7; uint8_t *modulus = NULL, *priv_exp = NULL, *pub_exp = NULL; int mod_len, priv_len, pub_len; #ifdef CONFIG_BIGINT_CRT uint8_t *p = NULL, *q = NULL, *dP = NULL, *dQ = NULL, *qInv = NULL; int p_len, q_len, dP_len, dQ_len, qInv_len; #endif /* not in der format */ if (buf[0] != ASN1_SEQUENCE) /* basic sanity check */ { #ifdef CONFIG_SSL_FULL_MODE printf("Error: This is not a valid ASN.1 file\n"); #endif return X509_INVALID_PRIV_KEY; } /* initialise the RNG */ RNG_initialize(buf, len); mod_len = asn1_get_int(buf, &offset, &modulus); pub_len = asn1_get_int(buf, &offset, &pub_exp); priv_len = asn1_get_int(buf, &offset, &priv_exp); if (mod_len <= 0 || pub_len <= 0 || priv_len <= 0) return X509_INVALID_PRIV_KEY; #ifdef CONFIG_BIGINT_CRT p_len = asn1_get_int(buf, &offset, &p); q_len = asn1_get_int(buf, &offset, &q); dP_len = asn1_get_int(buf, &offset, &dP); dQ_len = asn1_get_int(buf, &offset, &dQ); qInv_len = asn1_get_int(buf, &offset, &qInv); if (p_len <= 0 || q_len <= 0 || dP_len <= 0 || dQ_len <= 0 || qInv_len <= 0) return X509_INVALID_PRIV_KEY; RSA_priv_key_new(rsa_ctx, modulus, mod_len, pub_exp, pub_len, priv_exp, priv_len, p, p_len, q, p_len, dP, dP_len, dQ, dQ_len, qInv, qInv_len); free(p); free(q); free(dP); free(dQ); free(qInv); #else RSA_priv_key_new(rsa_ctx, modulus, mod_len, pub_exp, pub_len, priv_exp, priv_len); #endif free(modulus); free(priv_exp); free(pub_exp); return X509_OK; }
int Curl_axtls_random(struct SessionHandle *data, unsigned char *entropy, size_t length) { static bool ssl_seeded = FALSE; (void)data; if(!ssl_seeded) { ssl_seeded = TRUE; /* Initialize the seed if not already done. This call is not exactly thread * safe (and neither is the ssl_seeded check), but the worst effect of a * race condition is that some global resources will leak. */ RNG_initialize(); } get_random((int)length, entropy); return 0; }
static SQRESULT sq_axtls_rng_initialize(HSQUIRRELVM v) { RNG_initialize(); return 0; }