Thanks for your reply.
I meet so many problem when compile OpenSSL RSA for trusty.
My example TA service with openssl rsa part as follows:
RSA* create_rsa_from_mem_with_type(char* key, int pubtype) {
RSA *rsa = NULL;
BIO *bio = NULL;
bio = BIO_new(BIO_s_mem());
if(bio == NULL) {
TLOGI("bio is NULL!\n");
}
BIO_puts(bio, key);
if (pubtype == 1) {
rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL);
} else {
rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
}
if(rsa == NULL) {
TLOGI("wrong again\n");
}
BIO_free(bio);
return rsa;
}
int public_encrypt(unsigned char* data, int data_len, char* key, unsigned char* encrypted) {
RSA* rsa = create_rsa_from_mem_with_type(key, 1);
if (rsa != NULL) {
int result = RSA_public_encrypt(data_len, data, encrypted, rsa, RSA_PKCS1_PADDING);
RSA_free(rsa);
return result;
}
return 0;
}
int private_decrypt(unsigned char * enc_data,int data_len, char * key, unsigned char *decrypted)
{
RSA * rsa = create_rsa_from_mem_with_type(key, 0);
if (rsa != NULL ) {
int result = RSA_private_decrypt(data_len, enc_data, decrypted, rsa, RSA_PKCS1_PADDING);
RSA_free(rsa);
return result;
}
return 0;
}
But I got many problems when compile:
First I got “undefined reference to xxx” error, then I added related sources(openssl crypto/xx/xx.c) to the Crypto-config-trusty.mk that can fix some problems.
Crypto-config-trusty.mk part as here:
common_src_files := \
...
\
crypto/evp/evp_key.c \
crypto/evp/encode.c \
crypto/evp/p5_crpt.c \
crypto/evp/p5_crpt2.c \
crypto/pkcs12/p12_crpt.c \
crypto/pkcs12/p12_p8d.c \
crypto/pkcs12/p12_decr.c \
crypto/pkcs12/p12_key.c \
crypto/asn1/p5_pbe.c \
crypto/asn1/p5_pbev2.c \
crypto/evp/m_md5.c \
crypto/md5/md5_dgst.c \
crypto/md5/md5_one.c \
I still had errors for “Undefined reference to EVP_md5”, I think I have added “crypto/evp/m_md5”, but not work. I want to know if I’m on the right track.
Other problem: When I add crypto/ui/ui_openssl.c, I encounter a mismatch of ‘ioctl parameters’, which should be related to the definition of ioctl in trusty.
Finaly, I was wondering if the official has tried to tune this code, can you provide a demo?