4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 #include <sys/types.h>
31 #include <security/cryptoki.h>
32 #include "softSession.h"
33 #include "softObject.h"
34 #include "softCrypt.h"
38 * Allocate context for the active encryption or decryption operation, and
39 * generate AES key schedule to speed up the operation.
42 soft_aes_crypt_init_common(soft_session_t
*session_p
,
43 CK_MECHANISM_PTR pMechanism
, soft_object_t
*key_p
,
47 soft_aes_ctx_t
*soft_aes_ctx
;
49 soft_aes_ctx
= calloc(1, sizeof (soft_aes_ctx_t
));
50 if (soft_aes_ctx
== NULL
) {
51 return (CKR_HOST_MEMORY
);
54 soft_aes_ctx
->key_sched
= aes_alloc_keysched(&size
, 0);
56 if (soft_aes_ctx
->key_sched
== NULL
) {
58 return (CKR_HOST_MEMORY
);
61 soft_aes_ctx
->keysched_len
= size
;
63 (void) pthread_mutex_lock(&session_p
->session_mutex
);
65 /* Called by C_EncryptInit. */
66 session_p
->encrypt
.context
= soft_aes_ctx
;
67 session_p
->encrypt
.mech
.mechanism
= pMechanism
->mechanism
;
69 /* Called by C_DecryptInit. */
70 session_p
->decrypt
.context
= soft_aes_ctx
;
71 session_p
->decrypt
.mech
.mechanism
= pMechanism
->mechanism
;
73 (void) pthread_mutex_unlock(&session_p
->session_mutex
);
76 * If this is a non-sensitive key and it does NOT have
77 * a key schedule yet, then allocate one and expand it.
78 * Otherwise, if it's a non-sensitive key, and it DOES have
79 * a key schedule already attached to it, just copy the
80 * pre-expanded schedule to the context and avoid the
81 * extra key schedule expansion operation.
83 if (!(key_p
->bool_attr_mask
& SENSITIVE_BOOL_ON
)) {
84 if (OBJ_KEY_SCHED(key_p
) == NULL
) {
87 (void) pthread_mutex_lock(&key_p
->object_mutex
);
88 if (OBJ_KEY_SCHED(key_p
) == NULL
) {
89 ks
= aes_alloc_keysched(&size
, 0);
91 (void) pthread_mutex_unlock(
92 &key_p
->object_mutex
);
94 return (CKR_HOST_MEMORY
);
98 aes_init_keysched(OBJ_SEC_VALUE(key_p
), (uint_t
)
99 (OBJ_SEC_VALUE_LEN(key_p
) * 8), ks
);
100 #else /* !__sparcv9 */
101 aes_init_keysched(OBJ_SEC_VALUE(key_p
),
102 (OBJ_SEC_VALUE_LEN(key_p
) * 8), ks
);
103 #endif /* __sparcv9 */
104 OBJ_KEY_SCHED_LEN(key_p
) = size
;
105 OBJ_KEY_SCHED(key_p
) = ks
;
107 (void) pthread_mutex_unlock(&key_p
->object_mutex
);
109 (void) memcpy(soft_aes_ctx
->key_sched
, OBJ_KEY_SCHED(key_p
),
110 OBJ_KEY_SCHED_LEN(key_p
));
111 soft_aes_ctx
->keysched_len
= OBJ_KEY_SCHED_LEN(key_p
);
114 * Initialize key schedule for AES. aes_init_keysched()
115 * requires key length in bits.
119 aes_init_keysched(OBJ_SEC_VALUE(key_p
), (uint_t
)
120 (OBJ_SEC_VALUE_LEN(key_p
) * 8), soft_aes_ctx
->key_sched
);
121 #else /* !__sparcv9 */
122 aes_init_keysched(OBJ_SEC_VALUE(key_p
),
123 (OBJ_SEC_VALUE_LEN(key_p
) * 8), soft_aes_ctx
->key_sched
);
124 #endif /* __sparcv9 */
131 * soft_aes_encrypt_common()
134 * session_p: pointer to soft_session_t struct
135 * pData: pointer to the input data to be encrypted
136 * ulDataLen: length of the input data
137 * pEncrypted: pointer to the output data after encryption
138 * pulEncryptedLen: pointer to the length of the output data
139 * update: boolean flag indicates caller is soft_encrypt
140 * or soft_encrypt_update
143 * This function calls the corresponding encrypt routine based
148 * CKR_BUFFER_TOO_SMALL: the output buffer provided by application
150 * CKR_FUNCTION_FAILED: encrypt function failed
151 * CKR_DATA_LEN_RANGE: the input data is not a multiple of blocksize
154 soft_aes_encrypt_common(soft_session_t
*session_p
, CK_BYTE_PTR pData
,
155 CK_ULONG ulDataLen
, CK_BYTE_PTR pEncrypted
,
156 CK_ULONG_PTR pulEncryptedLen
, boolean_t update
)
161 soft_aes_ctx_t
*soft_aes_ctx
=
162 (soft_aes_ctx_t
*)session_p
->encrypt
.context
;
164 CK_MECHANISM_TYPE mechanism
= session_p
->encrypt
.mech
.mechanism
;
165 CK_BYTE
*in_buf
= NULL
;
166 CK_BYTE
*out_buf
= NULL
;
171 if (mechanism
== CKM_AES_CTR
)
175 * AES only takes input length that is a multiple of blocksize
176 * for C_Encrypt function with the mechanism CKM_AES_ECB or
179 * AES allows any input length for C_Encrypt function with the
180 * mechanism CKM_AES_CBC_PAD and for C_EncryptUpdate function.
182 if ((!update
) && (mechanism
!= CKM_AES_CBC_PAD
)) {
183 if ((ulDataLen
% AES_BLOCK_LEN
) != 0) {
184 rv
= CKR_DATA_LEN_RANGE
;
191 * Called by C_Encrypt
193 if (mechanism
== CKM_AES_CBC_PAD
) {
195 * For CKM_AES_CBC_PAD, compute output length to
196 * count for the padding. If the length of input
197 * data is a multiple of blocksize, then make output
198 * length to be the sum of the input length and
199 * one blocksize. Otherwise, output length will
200 * be rounded up to the next multiple of blocksize.
202 out_len
= AES_BLOCK_LEN
*
203 (ulDataLen
/ AES_BLOCK_LEN
+ 1);
206 * For non-padding mode, the output length will
207 * be same as the input length.
213 * If application asks for the length of the output buffer
214 * to hold the ciphertext?
216 if (pEncrypted
== NULL
) {
217 *pulEncryptedLen
= out_len
;
221 /* Is the application-supplied buffer large enough? */
222 if (*pulEncryptedLen
< out_len
) {
223 *pulEncryptedLen
= out_len
;
224 return (CKR_BUFFER_TOO_SMALL
);
227 /* Encrypt pad bytes in a separate operation */
228 if (mechanism
== CKM_AES_CBC_PAD
) {
229 out_len
-= AES_BLOCK_LEN
;
233 out_buf
= pEncrypted
;
236 * Called by C_EncryptUpdate
238 * Add the lengths of last remaining data and current
239 * plaintext together to get the total input length.
241 total_len
= soft_aes_ctx
->remain_len
+ ulDataLen
;
244 * If the total input length is less than one blocksize,
245 * or if the total input length is just one blocksize and
246 * the mechanism is CKM_AES_CBC_PAD, we will need to delay
247 * encryption until when more data comes in next
248 * C_EncryptUpdate or when C_EncryptFinal is called.
250 if ((total_len
< AES_BLOCK_LEN
) ||
251 ((mechanism
== CKM_AES_CBC_PAD
) &&
252 (total_len
== AES_BLOCK_LEN
))) {
253 if (pEncrypted
!= NULL
) {
255 * Save input data and its length in
256 * the remaining buffer of AES context.
258 (void) memcpy(soft_aes_ctx
->data
+
259 soft_aes_ctx
->remain_len
, pData
, ulDataLen
);
260 soft_aes_ctx
->remain_len
+= ulDataLen
;
263 /* Set encrypted data length to 0. */
264 *pulEncryptedLen
= 0;
268 /* Compute the length of remaing data. */
269 remain
= total_len
% AES_BLOCK_LEN
;
272 * Make sure that the output length is a multiple of
275 out_len
= total_len
- remain
;
278 * If application asks for the length of the output buffer
279 * to hold the ciphertext?
281 if (pEncrypted
== NULL
) {
282 *pulEncryptedLen
= out_len
;
286 /* Is the application-supplied buffer large enough? */
287 if (*pulEncryptedLen
< out_len
) {
288 *pulEncryptedLen
= out_len
;
289 return (CKR_BUFFER_TOO_SMALL
);
292 if (soft_aes_ctx
->remain_len
!= 0) {
294 * Copy last remaining data and current input data
295 * to the output buffer.
297 (void) memmove(pEncrypted
+ soft_aes_ctx
->remain_len
,
298 pData
, out_len
- soft_aes_ctx
->remain_len
);
299 (void) memcpy(pEncrypted
, soft_aes_ctx
->data
,
300 soft_aes_ctx
->remain_len
);
301 bzero(soft_aes_ctx
->data
, soft_aes_ctx
->remain_len
);
307 out_buf
= pEncrypted
;
312 * Begin Encryption now.
323 for (i
= 0; i
< out_len
; i
+= AES_BLOCK_LEN
) {
324 tmp_inbuf
= &in_buf
[i
];
325 tmp_outbuf
= &out_buf
[i
];
326 /* Crunch one block of data for AES. */
327 (void) aes_encrypt_block(soft_aes_ctx
->key_sched
,
328 tmp_inbuf
, tmp_outbuf
);
333 * For encrypt update, if there is a remaining
334 * data, save it and its length in the context.
337 (void) memcpy(soft_aes_ctx
->data
, pData
+
338 (ulDataLen
- remain
), remain
);
339 soft_aes_ctx
->remain_len
= remain
;
342 *pulEncryptedLen
= out_len
;
348 case CKM_AES_CBC_PAD
:
352 out
.cd_format
= CRYPTO_DATA_RAW
;
354 out
.cd_length
= out_len
;
355 out
.cd_raw
.iov_base
= (char *)out_buf
;
356 out
.cd_raw
.iov_len
= out_len
;
358 /* Encrypt multiple blocks of data. */
359 rc
= aes_encrypt_contiguous_blocks(
360 (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
,
361 (char *)in_buf
, out_len
, &out
);
368 * For encrypt update, if there is remaining data,
369 * save it and its length in the context.
372 (void) memcpy(soft_aes_ctx
->data
, pData
+
373 (ulDataLen
- remain
), remain
);
374 soft_aes_ctx
->remain_len
= remain
;
375 } else if (mechanism
== CKM_AES_CBC_PAD
) {
377 * Save the remainder of the input
378 * block in a temporary block because
379 * we dont want to overrun the buffer
380 * by tacking on pad bytes.
382 CK_BYTE tmpblock
[AES_BLOCK_LEN
];
383 (void) memcpy(tmpblock
, in_buf
+ out_len
,
384 ulDataLen
- out_len
);
385 soft_add_pkcs7_padding(tmpblock
+
386 (ulDataLen
- out_len
),
387 AES_BLOCK_LEN
, ulDataLen
- out_len
);
389 out
.cd_offset
= out_len
;
390 out
.cd_length
= AES_BLOCK_LEN
;
391 out
.cd_raw
.iov_base
= (char *)out_buf
;
392 out
.cd_raw
.iov_len
= out_len
+ AES_BLOCK_LEN
;
394 /* Encrypt last block containing pad bytes. */
395 rc
= aes_encrypt_contiguous_blocks(
396 (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
,
397 (char *)tmpblock
, AES_BLOCK_LEN
, &out
);
399 out_len
+= AES_BLOCK_LEN
;
403 *pulEncryptedLen
= out_len
;
407 *pulEncryptedLen
= 0;
408 rv
= CKR_FUNCTION_FAILED
;
415 out
.cd_format
= CRYPTO_DATA_RAW
;
417 out
.cd_length
= *pulEncryptedLen
;
418 out
.cd_raw
.iov_base
= (char *)pEncrypted
;
419 out
.cd_raw
.iov_len
= *pulEncryptedLen
;
421 rc
= aes_encrypt_contiguous_blocks(soft_aes_ctx
->aes_cbc
,
422 (char *)pData
, ulDataLen
, &out
);
425 *pulEncryptedLen
= 0;
426 rv
= CKR_FUNCTION_FAILED
;
430 * Since AES counter mode is a stream cipher, we call
431 * aes_counter_final() to pick up any remaining bytes.
432 * It is an internal function that does not destroy
433 * the context like *normal* final routines.
435 if (((aes_ctx_t
*)soft_aes_ctx
->aes_cbc
)->ac_remainder_len
> 0)
436 rc
= ctr_mode_final(soft_aes_ctx
->aes_cbc
, &out
,
445 * The following code will be executed if the caller is
446 * soft_encrypt() or an error occurred. The encryption
447 * operation will be terminated so we need to do some cleanup.
450 (void) pthread_mutex_lock(&session_p
->session_mutex
);
451 aes_ctx
= (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
;
452 if (aes_ctx
!= NULL
) {
453 bzero(aes_ctx
->ac_keysched
, aes_ctx
->ac_keysched_len
);
454 free(soft_aes_ctx
->aes_cbc
);
457 bzero(soft_aes_ctx
->key_sched
, soft_aes_ctx
->keysched_len
);
458 free(soft_aes_ctx
->key_sched
);
459 free(session_p
->encrypt
.context
);
460 session_p
->encrypt
.context
= NULL
;
461 (void) pthread_mutex_unlock(&session_p
->session_mutex
);
468 * soft_aes_decrypt_common()
471 * session_p: pointer to soft_session_t struct
472 * pEncrypted: pointer to the input data to be decrypted
473 * ulEncryptedLen: length of the input data
474 * pData: pointer to the output data
475 * pulDataLen: pointer to the length of the output data
476 * Update: boolean flag indicates caller is soft_decrypt
477 * or soft_decrypt_update
480 * This function calls the corresponding decrypt routine based
485 * CKR_BUFFER_TOO_SMALL: the output buffer provided by application
487 * CKR_ENCRYPTED_DATA_LEN_RANGE: the input data is not a multiple
489 * CKR_FUNCTION_FAILED: decrypt function failed
492 soft_aes_decrypt_common(soft_session_t
*session_p
, CK_BYTE_PTR pEncrypted
,
493 CK_ULONG ulEncryptedLen
, CK_BYTE_PTR pData
,
494 CK_ULONG_PTR pulDataLen
, boolean_t update
)
499 soft_aes_ctx_t
*soft_aes_ctx
=
500 (soft_aes_ctx_t
*)session_p
->decrypt
.context
;
502 CK_MECHANISM_TYPE mechanism
= session_p
->decrypt
.mech
.mechanism
;
503 CK_BYTE
*in_buf
= NULL
;
504 CK_BYTE
*out_buf
= NULL
;
509 if (mechanism
== CKM_AES_CTR
)
513 * AES only takes input length that is a multiple of 16 bytes
514 * for C_Decrypt function with the mechanism CKM_AES_ECB,
515 * CKM_AES_CBC or CKM_AES_CBC_PAD.
517 * AES allows any input length for C_DecryptUpdate function.
521 * Called by C_Decrypt
523 if ((ulEncryptedLen
% AES_BLOCK_LEN
) != 0) {
524 rv
= CKR_ENCRYPTED_DATA_LEN_RANGE
;
529 * If application asks for the length of the output buffer
530 * to hold the plaintext?
533 *pulDataLen
= ulEncryptedLen
;
537 /* Is the application-supplied buffer large enough? */
538 if (mechanism
!= CKM_AES_CBC_PAD
) {
539 if (*pulDataLen
< ulEncryptedLen
) {
540 *pulDataLen
= ulEncryptedLen
;
541 return (CKR_BUFFER_TOO_SMALL
);
543 out_len
= ulEncryptedLen
;
546 * For CKM_AES_CBC_PAD, we don't know how
547 * many bytes for padding at this time, so
548 * we'd assume one block was padded.
550 if (*pulDataLen
< (ulEncryptedLen
- AES_BLOCK_LEN
)) {
551 *pulDataLen
= ulEncryptedLen
- AES_BLOCK_LEN
;
552 return (CKR_BUFFER_TOO_SMALL
);
554 out_len
= ulEncryptedLen
- AES_BLOCK_LEN
;
560 * Called by C_DecryptUpdate
562 * Add the lengths of last remaining data and current
563 * input data together to get the total input length.
565 total_len
= soft_aes_ctx
->remain_len
+ ulEncryptedLen
;
568 * If the total input length is less than one blocksize,
569 * or if the total input length is just one blocksize and
570 * the mechanism is CKM_AES_CBC_PAD, we will need to delay
571 * decryption until when more data comes in next
572 * C_DecryptUpdate or when C_DecryptFinal is called.
574 if ((total_len
< AES_BLOCK_LEN
) ||
575 ((mechanism
== CKM_AES_CBC_PAD
) &&
576 (total_len
== AES_BLOCK_LEN
))) {
579 * Save input data and its length in
580 * the remaining buffer of AES context.
582 (void) memcpy(soft_aes_ctx
->data
+
583 soft_aes_ctx
->remain_len
,
584 pEncrypted
, ulEncryptedLen
);
585 soft_aes_ctx
->remain_len
+= ulEncryptedLen
;
588 /* Set output data length to 0. */
593 /* Compute the length of remaing data. */
594 remain
= total_len
% AES_BLOCK_LEN
;
597 * Make sure that the output length is a multiple of
600 out_len
= total_len
- remain
;
602 if (mechanism
== CKM_AES_CBC_PAD
) {
604 * If the input data length is a multiple of
605 * blocksize, then save the last block of input
606 * data in the remaining buffer. C_DecryptFinal
607 * will handle this last block of data.
610 remain
= AES_BLOCK_LEN
;
611 out_len
-= AES_BLOCK_LEN
;
616 * If application asks for the length of the output buffer
617 * to hold the plaintext?
620 *pulDataLen
= out_len
;
625 * Is the application-supplied buffer large enough?
627 if (*pulDataLen
< out_len
) {
628 *pulDataLen
= out_len
;
629 return (CKR_BUFFER_TOO_SMALL
);
632 if (soft_aes_ctx
->remain_len
!= 0) {
634 * Copy last remaining data and current input data
635 * to the output buffer.
637 (void) memmove(pData
+ soft_aes_ctx
->remain_len
,
638 pEncrypted
, out_len
- soft_aes_ctx
->remain_len
);
639 (void) memcpy(pData
, soft_aes_ctx
->data
,
640 soft_aes_ctx
->remain_len
);
641 bzero(soft_aes_ctx
->data
, soft_aes_ctx
->remain_len
);
663 for (i
= 0; i
< out_len
; i
+= AES_BLOCK_LEN
) {
664 tmp_inbuf
= &in_buf
[i
];
665 tmp_outbuf
= &out_buf
[i
];
666 /* Crunch one block of data for AES. */
667 (void) aes_decrypt_block(soft_aes_ctx
->key_sched
,
668 tmp_inbuf
, tmp_outbuf
);
673 * For decrypt update, if there is a remaining
674 * data, save it and its length in the context.
677 (void) memcpy(soft_aes_ctx
->data
, pEncrypted
+
678 (ulEncryptedLen
- remain
), remain
);
679 soft_aes_ctx
->remain_len
= remain
;
682 *pulDataLen
= out_len
;
688 case CKM_AES_CBC_PAD
:
692 uint8_t last_block
[AES_BLOCK_LEN
];
694 out
.cd_format
= CRYPTO_DATA_RAW
;
696 out
.cd_length
= out_len
;
697 out
.cd_raw
.iov_base
= (char *)out_buf
;
698 out
.cd_raw
.iov_len
= out_len
;
700 /* Decrypt multiple blocks of data. */
701 rc
= aes_decrypt_contiguous_blocks(
702 (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
,
703 (char *)in_buf
, out_len
, &out
);
708 if ((mechanism
== CKM_AES_CBC_PAD
) && (!update
)) {
709 /* Decrypt last block containing pad bytes. */
711 out
.cd_length
= AES_BLOCK_LEN
;
712 out
.cd_raw
.iov_base
= (char *)last_block
;
713 out
.cd_raw
.iov_len
= AES_BLOCK_LEN
;
715 /* Decrypt last block containing pad bytes. */
716 rc
= aes_decrypt_contiguous_blocks(
717 (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
,
718 (char *)in_buf
+ out_len
, AES_BLOCK_LEN
, &out
);
724 * Remove padding bytes after decryption of
725 * ciphertext block to produce the original
728 rv
= soft_remove_pkcs7_padding(last_block
,
729 AES_BLOCK_LEN
, &rem_len
);
732 (void) memcpy(out_buf
+ out_len
,
733 last_block
, rem_len
);
734 *pulDataLen
= out_len
+ rem_len
;
740 *pulDataLen
= out_len
;
745 * For decrypt update, if there is remaining data,
746 * save it and its length in the context.
749 (void) memcpy(soft_aes_ctx
->data
, pEncrypted
+
750 (ulEncryptedLen
- remain
), remain
);
751 soft_aes_ctx
->remain_len
= remain
;
758 rv
= CKR_FUNCTION_FAILED
;
765 out
.cd_format
= CRYPTO_DATA_RAW
;
767 out
.cd_length
= *pulDataLen
;
768 out
.cd_raw
.iov_base
= (char *)pData
;
769 out
.cd_raw
.iov_len
= *pulDataLen
;
771 rc
= aes_decrypt_contiguous_blocks(soft_aes_ctx
->aes_cbc
,
772 (char *)pEncrypted
, ulEncryptedLen
, &out
);
776 rv
= CKR_FUNCTION_FAILED
;
781 * Since AES counter mode is a stream cipher, we call
782 * aes_counter_final() to pick up any remaining bytes.
783 * It is an internal function that does not destroy
784 * the context like *normal* final routines.
786 if (((aes_ctx_t
*)soft_aes_ctx
->aes_cbc
)->ac_remainder_len
788 rc
= ctr_mode_final(soft_aes_ctx
->aes_cbc
, &out
,
790 if (rc
== CRYPTO_DATA_LEN_RANGE
)
791 rc
= CRYPTO_ENCRYPTED_DATA_LEN_RANGE
;
800 * The following code will be executed if the caller is
801 * soft_decrypt() or an error occurred. The decryption
802 * operation will be terminated so we need to do some cleanup.
805 (void) pthread_mutex_lock(&session_p
->session_mutex
);
806 aes_ctx
= (aes_ctx_t
*)soft_aes_ctx
->aes_cbc
;
807 if (aes_ctx
!= NULL
) {
808 bzero(aes_ctx
->ac_keysched
, aes_ctx
->ac_keysched_len
);
809 free(soft_aes_ctx
->aes_cbc
);
812 bzero(soft_aes_ctx
->key_sched
, soft_aes_ctx
->keysched_len
);
813 free(soft_aes_ctx
->key_sched
);
814 free(session_p
->decrypt
.context
);
815 session_p
->decrypt
.context
= NULL
;
816 (void) pthread_mutex_unlock(&session_p
->session_mutex
);
823 * Allocate and initialize a context for AES CBC mode of operation.
826 aes_cbc_ctx_init(void *key_sched
, size_t size
, uint8_t *ivec
)
831 if ((cbc_ctx
= calloc(1, sizeof (cbc_ctx_t
))) == NULL
)
834 cbc_ctx
->cbc_keysched
= key_sched
;
835 cbc_ctx
->cbc_keysched_len
= size
;
837 (void) memcpy(&cbc_ctx
->cbc_iv
[0], ivec
, AES_BLOCK_LEN
);
839 cbc_ctx
->cbc_lastp
= (uint8_t *)cbc_ctx
->cbc_iv
;
840 cbc_ctx
->cbc_flags
|= CBC_MODE
;
846 * Allocate and initialize a context for AES CTR mode of operation.
849 aes_ctr_ctx_init(void *key_sched
, size_t size
, uint8_t *param
)
853 CK_AES_CTR_PARAMS
*pp
;
855 /* LINTED: pointer alignment */
856 pp
= (CK_AES_CTR_PARAMS
*)param
;
858 if ((ctr_ctx
= calloc(1, sizeof (ctr_ctx_t
))) == NULL
)
861 ctr_ctx
->ctr_keysched
= key_sched
;
862 ctr_ctx
->ctr_keysched_len
= size
;
864 if (ctr_init_ctx(ctr_ctx
, pp
->ulCounterBits
, pp
->cb
, aes_copy_block
)