Created
April 28, 2011 22:43
-
-
Save cchandler/947507 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int errors = 0; | |
CK_RV rv; | |
CK_OBJECT_HANDLE privKeyObject; | |
CK_SESSION_HANDLE sess; | |
CK_MECHANISM_TYPE *mechs = NULL; | |
CK_SESSION_INFO sessionInfo; | |
CK_ULONG j, n, num_mechs = 0; | |
char *label; | |
rv = p11->C_OpenSession(slot, CKF_SERIAL_SESSION, NULL, NULL, &sess); | |
if (rv != CKR_OK) | |
p11_fatal("C_OpenSession", rv); | |
rv = p11->C_GetSessionInfo(sess, &sessionInfo); | |
if (rv != CKR_OK) | |
p11_fatal("C_OpenSession", rv); | |
if ((sessionInfo.state & CKS_RO_USER_FUNCTIONS) == 0) { | |
printf("Symmetric keys: not logged in, skipping symmetric tests\n"); | |
return errors; | |
} | |
CK_MECHANISM mechanism = { | |
CKM_DES3_KEY_GEN, NULL_PTR, 0 | |
}; | |
CK_BBOOL _true = TRUE; | |
CK_BBOOL _false = FALSE; | |
CK_ULONG valueLen= 112; | |
CK_ATTRIBUTE template[] = { | |
{CKA_TOKEN, &_false, sizeof(_false)}, | |
{CKA_SIGN, &_false, sizeof(_false)}, | |
{CKA_ENCRYPT, &_true, sizeof(_true)}, | |
{CKA_VALUE_LEN, &valueLen, sizeof(valueLen)}, | |
}; | |
CK_OBJECT_HANDLE hKey; | |
rv = p11->C_GenerateKey(sess, &mechanism, template, 4, &hKey); | |
if (rv != CKR_OK) | |
p11_fatal("C_GenerateKey", rv); | |
CK_MECHANISM encrypt_mechanism = { | |
CKM_DES3_ECB, NULL_PTR, 0 | |
}; | |
show_object(sess, hKey); | |
rv = p11->C_EncryptInit(sess, &encrypt_mechanism, hKey); | |
if (rv != CKR_OK) | |
p11_fatal("C_EncryptInit", rv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment