8 #ifndef _CRYPTCTX_DEFINED
10 #define _CRYPTCTX_DEFINED
17 #ifndef _STREAM_DEFINED
18 #if defined( INC_ALL )
25 #if defined( INC_ALL )
31 #if ( defined( USE_ECDH ) || defined( USE_ECDSA ) ) && !defined( HEADER_EC_H )
32 #if defined( INC_ALL )
39 #ifndef _CRYPTCAP_DEFINED
40 #if defined( INC_ALL )
94 #define CONTEXT_FLAG_NONE 0x0000
95 #define CONTEXT_FLAG_KEY_SET 0x0001
96 #define CONTEXT_FLAG_IV_SET 0x0002
97 #define CONTEXT_FLAG_ISPUBLICKEY 0x0004
98 #define CONTEXT_FLAG_ISPRIVATEKEY 0x0008
99 #define CONTEXT_FLAG_DUMMY 0x0010
100 #define CONTEXT_FLAG_DUMMY_INITED 0x0020
101 #define CONTEXT_FLAG_PERSISTENT 0x0040
102 #define CONTEXT_FLAG_SIDECHANNELPROTECTION \
104 #define CONTEXT_FLAG_HASH_INITED 0x0100
105 #define CONTEXT_FLAG_HASH_DONE 0x0200
106 #define CONTEXT_FLAG_PGPKEYID_SET 0x0400
107 #define CONTEXT_FLAG_OPENPGPKEYID_SET 0x0800
108 #define CONTEXT_FLAG_STATICCONTEXT 0x1000
109 #define CONTEXT_FLAG_MAX 0x1FFF
119 #define DLP_OVERFLOW_SIZE bitsToBytes( 32 )
142 #define needsSecureMemory( contextType ) \
143 ( contextType == CONTEXT_CONV || contextType == CONTEXT_MAC || \
144 contextType == CONTEXT_GENERIC )
194 time_t pgpCreationTime;
209 #if defined( USE_ECDH ) || defined( USE_ECDSA )
216 #if defined( USE_ECDH ) || defined( USE_ECDSA )
230 #if defined( USE_ECDH ) || defined( USE_ECDSA )
235 #define CONTEXT_FLAG_PBO 0x08
247 int publicKeyInfoSize;
270 const
char *accessKey,
272 const
int accessKeyLen );
279 const
char *accessKey,
281 const
int accessKeyLen );
358 #define ctxConv keyingInfo.convInfo
359 #define ctxPKC keyingInfo.pkcInfo
360 #define ctxHash keyingInfo.hashInfo
361 #define ctxMAC keyingInfo.macInfo
362 #define ctxGeneric keyingInfo.genericInfo
390 long deviceObject, altDeviceObject;
418 int ( *encryptFunction )(
INOUT struct
CI *contextInfoPtr,
422 int ( *decryptFunction )(
INOUT struct
CI *contextInfoPtr,
442 #define dlpParam_p param1
443 #define dlpParam_g param2
444 #define dlpParam_q param3
445 #define dlpParam_y param4
446 #define dlpParam_x param5
447 #define dlpTmp1 param6
448 #define dlpTmp2 param7
449 #define dlpTmp3 param8
450 #define dhParam_yPrime param8
451 #define dlpParam_mont_p montCTX1
453 #define rsaParam_n param1
454 #define rsaParam_e param2
455 #define rsaParam_d param3
456 #define rsaParam_p param4
457 #define rsaParam_q param5
458 #define rsaParam_u param6
459 #define rsaParam_exponent1 param7
460 #define rsaParam_exponent2 param8
461 #define rsaParam_blind_k blind1
462 #define rsaParam_blind_kInv blind2
463 #define rsaParam_mont_n montCTX1
464 #define rsaParam_mont_p montCTX2
465 #define rsaParam_mont_q montCTX3
467 #define eccParam_p param1
468 #define eccParam_a param2
469 #define eccParam_b param3
470 #define eccParam_gx param4
471 #define eccParam_gy param5
472 #define eccParam_n param6
473 #define eccParam_h param7
474 #define eccParam_qx param8
475 #define eccParam_qy param9
476 #define eccParam_d param10
477 #define eccParam_mont_p montCTX1
478 #define eccParam_mont_n montCTX2
486 #define RSAPARAM_MIN_N MIN_PKCSIZE
487 #define RSAPARAM_MAX_N CRYPT_MAX_PKCSIZE
488 #define RSAPARAM_MIN_E 1
489 #define RSAPARAM_MAX_E 4
490 #define RSAPARAM_MIN_D MIN_PKCSIZE
491 #define RSAPARAM_MAX_D CRYPT_MAX_PKCSIZE
492 #define RSAPARAM_MIN_P MIN_PKCSIZE / 2
493 #define RSAPARAM_MAX_P CRYPT_MAX_PKCSIZE
494 #define RSAPARAM_MIN_Q MIN_PKCSIZE / 2
495 #define RSAPARAM_MAX_Q CRYPT_MAX_PKCSIZE
496 #define RSAPARAM_MIN_U MIN_PKCSIZE / 2
497 #define RSAPARAM_MAX_U CRYPT_MAX_PKCSIZE
498 #define RSAPARAM_MIN_EXP1 MIN_PKCSIZE / 2
499 #define RSAPARAM_MAX_EXP1 CRYPT_MAX_PKCSIZE
500 #define RSAPARAM_MIN_EXP2 MIN_PKCSIZE / 2
501 #define RSAPARAM_MAX_EXP2 CRYPT_MAX_PKCSIZE
503 #define DLPPARAM_MIN_P MIN_PKCSIZE
504 #define DLPPARAM_MAX_P CRYPT_MAX_PKCSIZE
505 #define DLPPARAM_MIN_G 1
506 #define DLPPARAM_MAX_G CRYPT_MAX_PKCSIZE
507 #define DLPPARAM_MIN_Q bitsToBytes( 128 )
508 #define DLPPARAM_MAX_Q CRYPT_MAX_PKCSIZE
509 #define DLPPARAM_MIN_Y MIN_PKCSIZE
510 #define DLPPARAM_MAX_Y CRYPT_MAX_PKCSIZE
511 #define DLPPARAM_MIN_X bitsToBytes( 128 )
512 #define DLPPARAM_MAX_X CRYPT_MAX_PKCSIZE
514 #define DLPPARAM_MIN_SIG_R DLPPARAM_MIN_Q
515 #define DLPPARAM_MIN_SIG_S DLPPARAM_MIN_Q
517 #define ECCPARAM_MIN_P MIN_PKCSIZE_ECC
518 #define ECCPARAM_MAX_P CRYPT_MAX_PKCSIZE_ECC
519 #define ECCPARAM_MIN_A MIN_PKCSIZE_ECC / 2
520 #define ECCPARAM_MAX_A CRYPT_MAX_PKCSIZE_ECC
521 #define ECCPARAM_MIN_B MIN_PKCSIZE_ECC / 2
522 #define ECCPARAM_MAX_B CRYPT_MAX_PKCSIZE_ECC
523 #define ECCPARAM_MIN_GX 1
524 #define ECCPARAM_MAX_GX CRYPT_MAX_PKCSIZE_ECC
525 #define ECCPARAM_MIN_GY 1
526 #define ECCPARAM_MAX_GY CRYPT_MAX_PKCSIZE_ECC
527 #define ECCPARAM_MIN_N MIN_PKCSIZE_ECC
528 #define ECCPARAM_MAX_N CRYPT_MAX_PKCSIZE_ECC
529 #define ECCPARAM_MIN_H MIN_PKCSIZE_ECC
530 #define ECCPARAM_MAX_H CRYPT_MAX_PKCSIZE_ECC
531 #define ECCPARAM_MIN_QX MIN_PKCSIZE_ECC / 2
532 #define ECCPARAM_MAX_QX CRYPT_MAX_PKCSIZE_ECC
533 #define ECCPARAM_MIN_QY MIN_PKCSIZE_ECC / 2
534 #define ECCPARAM_MAX_QY CRYPT_MAX_PKCSIZE_ECC
535 #define ECCPARAM_MIN_D MIN_PKCSIZE_ECC / 2
536 #define ECCPARAM_MAX_D CRYPT_MAX_PKCSIZE_ECC
538 #define ECCPARAM_MIN_SIG_R ECCPARAM_MIN_QX
539 #define ECCPARAM_MIN_SIG_S ECCPARAM_MIN_QX
551 #define CK( x ) bnStatus &= x
552 #define CKPTR( x ) bnStatus &= ( ( x ) == NULL ? 0 : 1 )
554 #define bnStatusOK( x ) bnStatus
555 #define bnStatusError( x ) ( !bnStatus )
556 #define getBnStatus( x ) ( bnStatus ? CRYPT_OK : CRYPT_ERROR_FAILED )
566 #define needsKey( contextInfoPtr ) \
567 !( ( contextInfoPtr )->flags & CONTEXT_FLAG_KEY_SET )
578 IN_FLAGS_Z( CREATEOBJECT )
const int objectFlags );
686 void clearTempBignums(
INOUT PKC_INFO *pkcInfo );
688 int initContextBignums(
INOUT PKC_INFO *pkcInfo,
689 IN_RANGE( 0, 3 )
const int sideChannelProtectionLevel,
692 void freeContextBignums(
INOUT PKC_INFO *pkcInfo,
695 int calculateBignumChecksum(
INOUT PKC_INFO *pkcInfo,
756 IN_BUFFER( inLength )
const void *inBuffer,
759 void ripemd160HashBufferAtomic(
OUT_BUFFER_C( outBufMaxLength, 20 )
BYTE *outBuffer,
761 IN_BUFFER( inLength )
const void *inBuffer,
766 IN_BUFFER( inLength )
const void *inBuffer,
769 void sha2HashBufferAtomic(
OUT_BUFFER_C( outBufMaxLength, 32 )
BYTE *outBuffer,
771 IN_BUFFER( inLength )
const void *inBuffer,
774 void sha2_ExtHashBufferAtomic(
OUT_BUFFER_C( outBufMaxLength, 64 )
BYTE *outBuffer,
776 IN_BUFFER( inLength )
const void *inBuffer,