implement kc_rsa_private_decrypt
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24202 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -119,6 +119,8 @@ kc_rsa_private_encrypt(int flen,
|
|||||||
CSSM_DATA sig, in;
|
CSSM_DATA sig, in;
|
||||||
int fret = 0;
|
int fret = 0;
|
||||||
|
|
||||||
|
if (padding != RSA_PKCS1_PADDING)
|
||||||
|
return -1;
|
||||||
|
|
||||||
cret = SecKeyGetCSSMKey(privKeyRef, &cssmKey);
|
cret = SecKeyGetCSSMKey(privKeyRef, &cssmKey);
|
||||||
if(cret) abort();
|
if(cret) abort();
|
||||||
@@ -157,7 +159,62 @@ static int
|
|||||||
kc_rsa_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
|
kc_rsa_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
|
||||||
RSA * rsa, int padding)
|
RSA * rsa, int padding)
|
||||||
{
|
{
|
||||||
|
struct kc_rsa *kc = RSA_get_app_data(rsa);
|
||||||
|
|
||||||
|
CSSM_RETURN cret;
|
||||||
|
OSStatus ret;
|
||||||
|
const CSSM_ACCESS_CREDENTIALS *creds;
|
||||||
|
SecKeyRef privKeyRef = (SecKeyRef)kc->item;
|
||||||
|
CSSM_CSP_HANDLE cspHandle;
|
||||||
|
const CSSM_KEY *cssmKey;
|
||||||
|
CSSM_CC_HANDLE handle = 0;
|
||||||
|
CSSM_DATA out, in, rem;
|
||||||
|
int fret = 0;
|
||||||
|
CSSM_SIZE outlen = 0;
|
||||||
|
char remdata[1024];
|
||||||
|
|
||||||
|
if (padding != RSA_PKCS1_PADDING)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
cret = SecKeyGetCSSMKey(privKeyRef, &cssmKey);
|
||||||
|
if(cret) abort();
|
||||||
|
|
||||||
|
cret = SecKeyGetCSPHandle(privKeyRef, &cspHandle);
|
||||||
|
if(cret) abort();
|
||||||
|
|
||||||
|
ret = SecKeyGetCredentials(privKeyRef, CSSM_ACL_AUTHORIZATION_DECRYPT,
|
||||||
|
kSecCredentialTypeDefault, &creds);
|
||||||
|
if(ret) abort();
|
||||||
|
|
||||||
|
|
||||||
|
ret = CSSM_CSP_CreateAsymmetricContext (cspHandle,
|
||||||
|
CSSM_ALGID_RSA,
|
||||||
|
creds,
|
||||||
|
cssmKey,
|
||||||
|
CSSM_PADDING_PKCS1,
|
||||||
|
&handle);
|
||||||
|
if(ret) abort();
|
||||||
|
|
||||||
|
in.Data = (uint8 *)from;
|
||||||
|
in.Length = flen;
|
||||||
|
|
||||||
|
out.Data = (uint8 *)to;
|
||||||
|
out.Length = kc->keysize;
|
||||||
|
|
||||||
|
rem.Data = (uint8 *)remdata;
|
||||||
|
rem.Length = sizeof(remdata);
|
||||||
|
|
||||||
|
cret = CSSM_DecryptData(handle, &in, 1, &out, 1, &outlen, &rem);
|
||||||
|
if(cret) {
|
||||||
|
/* cssmErrorString(cret); */
|
||||||
|
fret = -1;
|
||||||
|
} else
|
||||||
|
fret = out.Length;
|
||||||
|
|
||||||
|
if(handle)
|
||||||
|
CSSM_DeleteContext(handle);
|
||||||
|
|
||||||
|
return fret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Reference in New Issue
Block a user