I want to encrypt a large number of plaintext using PKCS#11 and SafeNet HSM devices. It will take a long time when I encrypt each plaintext one by one.
So It came to my mind if there are any methods in PKCS#11 which can encrypt several data at once?
I've found the below sample for encryption of multiple-part data in SafeNet C Programming manual which is using PKCS #11 APIs.
/* read, encrypt, digest and write the cipher text in chunks
*/ totbw = 0;
for ( ;; ) {
br = fread(buffer, 1, sizeof(buffer), ifp);
if ( br == 0 )
break;
/* digest */
/* encrypt */
curLen = sizeof(encbuffer);
rv = C_EncryptUpdate(hrSession, buffer, (CK_SIZE)br, encbuffer, &curLen);
CHECK_RV(FN "C_EncryptUpdate", rv);
if (rv) return 1;
/* write cipher text */
br = fwrite(encbuffer, 1, (int)curLen, ofp);
totbw += br;
}
It is mentioned in that manual:
For the encryption, we use C_EncryptUpdate, which continues a multiple-part encryption operation, processing another data part.
I want to know if this method can be used for encrypting multiple plaintexts at once or it will consider all buffer elements just as blocks of the same input data?
I'm looking for a solution which can encrypt multiple plaintexts but consider them as seperate item (not as blocks of a big single item).