Topic: How can i get the exponent and modulus of RSA public key with wolSSL?
the following is part of my project , is it possible to get both local and peer rsa public key's modulus and exponent using wolfssl 2.4.6? i found it some functions are empty, not implemented,i need to get the above modules and exponents to digest using sha256......thank you ~
void modulus_and_exponent(CYASSL_X509 *cert, uint8_t *acExponentBuf,
        uint8_t *acModulusBuf, int *elen, int *mlen)
{
    CYASSL_EVP_PKEY *pkey = CyaSSL_X509_get_pubkey(cert);
    CYASSL_RSA *rsa_public_key = NULL;
    rsa_public_key = CyaSSL_EVP_PKEY_get1_RSA(pkey);
    if (rsa_public_key != NULL)
    {
        *elen = CyaSSL_BN_bn2bin(rsa_public_key->e,acExponentBuf);
        *mlen = CyaSSL_BN_bn2bin(rsa_public_key->n,acModulusBuf);
    }
    else
    {
        printf("rsa_public_key==NULL!");
    }
}
int GetAlpha(uint8_t nonce, CYASSL *ssl, uint8_t *FinalDigestValue)
{
#define SHA_256_MAX 1024
    EVP_MD_CTX *mdctx;
    const EVP_MD *md;
    //get both modules and exponents
    CYASSL_X509 *LocalCert, *PeerCert;
    uint8_t acLocalExponentBuf[128] =
    { 0 };
    uint8_t acLocalModulusBuf[2048] =
    { 0 };
    uint8_t acPeerExponentBuf[128] =
    { 0 };
    uint8_t acPeerModulusBuf[2048] =
    { 0 };
    PeerCert = CyaSSL_get_peer_certificate(ssl);
    LocalCert = CyaSSL_get_certificate(ssl);
    /***********/
    int elenLoc,mlenLoc;
    int elenPeer,mlenPeer;
    /*************/
    modulus_and_exponent(LocalCert, acLocalExponentBuf, acLocalModulusBuf,&elenLoc, &mlenLoc);
    modulus_and_exponent(PeerCert, acPeerExponentBuf, acPeerModulusBuf, &elenPeer, &mlenPeer);
    
    /***********/
    RemoveLeadingNullBytes(acLocalExponentBuf,&elenLoc);
    RemoveLeadingNullBytes(acLocalModulusBuf,&mlenLoc);
    RemoveLeadingNullBytes(acPeerExponentBuf,&elenPeer);
    RemoveLeadingNullBytes(acPeerModulusBuf,&mlenPeer);
    /***********/
    
    Sha256 hash;
    byte   digest[SHA256_DIGEST_SIZE];
    double start, total, persec;
InitSha256(&hash);
    Sha256Update(&hash, acPeerModulusBuf, mlenPeer);
    Sha256Update(&hash, acPeerExponentBuf, elenPeer);
    Sha256Update(&hash, acLocalModulusBuf, mlenLoc);
    Sha256Update(&hash, acLocalExponentBuf, elenLoc);
    Sha256Update(&hash, &nonce, 1);
Sha256Final(&hash, digest);
strncpy(FinalDigestValue, digest, 1);
    return SHA256_DIGEST_SIZE;
}
