Crypto-C
Cryptographic Components for C
Copyright Notice
Contents
Page
N t e n t s
Key Info Types 245
Details of Crypto-C Functions 289
Crypto-C Error Types 351
References 359 Index 361
Page
Introduction
Organization
Crypto-C Environment
Memory Management
Code Example
Break If status = BEncryptInit
Code Example
Algorithm Object
As shown in , page 85, the format of info supplied to
Key Object
Bdemo Algorithm Chooser
Defining an Algorithm Chooser
Algorithm Chooser
Surrender Function
Non-zero Cancel operation
Surrender
Surrender function callback must have the following form
Continue with operation
Item Structure
Algorithm Info Types
1Sample Algorithm Type
AIBSSecretSharing
Pointer to a Bsecretsharingparams structure see above
Output considerations
AICBCIV8
AICBCIV16
On the algorithm object are undefined
For all randomAlgorithm arguments
AIDESCBCBSAFE1
Pointer to a BBSAFE1ENCRYPTIONPARAMS structure see above
Input constraints
AIDESCBCIV8
Token-based algorithm methods
Input that is a multiple of 8 bytes
AIDESCBCPadBER
Key info types for keyObject in BEncryptInit or BDecryptInit
AIDESCBCPadIV8
AIDESCBCPadBER, AIDESCBCPadPEM
AIDESCBCPadPEM
AIDESCBCPadIV8, AIDESCBCPadBER
AIDESEDE3CBCIV8
Decryption
Token-based algorithm methods
AIDESEDE3CBCPadBER
AIDESEDE3CBCPadIV8
AIDESEDE3CBCPadIV8
AIDESEDE3CBCPadBER
AIDESXCBCBSAFE1
Input constraints
AIDESXCBCIV8
Key info types for keyObject in BEncryptInit or BDecryptInit
AIDESXCBCPadBER
AIDESXCBCPadIV8
AIDESXCBCPadIV8
AIDESXCBCPadBER
AIDHKeyAgree
Pointer to an Adhkeyagreeparams structure
Initialized random algorithm to BKeyAgreePhase1
AIDHKeyAgreeBER
AIDHKeyAgree
AIDHParamGen
Pointer to an Adhparamgenparams structure
ExponentBits must be less than primeBits
Pointer to an Adhparamgenparams structure see above
Aidsa
Key info types for keyObject in BVerifyInit
Input constraints
Pointer to an Adsaparams structure see above
AIDSAKeyGen
Pointer to an Adsaparams structure
Amdsakeygen
AIDSAParamGen
Pointer to a Bdsaparamgenparams structure
Pointer to a Bdsaparamgenparams structure see above
Size of the subprime is always 160 bits
AIDSAWithSHA1
AIDSAWithSHA1BER
AIDSAWithSHA1BER
AIDSAWithSHA1
None
AIECAcceleratorTable
Pointer to an Item holding the accelerator table
AIECBuildAcceleratorTable
Pointer to a Becparams structure
An Aecparams structure
Size of the accelerator table may be found through a call to
AIECBuildPubKeyAccelTable
Crypto-C procedures to use with algorithm object
AIECDHKeyAgree
AIECDHKeyAgree
Aiecdsa
KIECPrivate or KIECPrivateBER
AIECDSAWithDigest
Pointer to a Bdigestspecifier structure
Key info types for keyObject in BSignInit
Aieces
AIECKeyGen
Characteristic
AIECParameters
Pointer to an Aecparams structure
Set the arguments as follows
Argument Values Comments
Possible values for FTX962NAMEDCURVETYPE are
FTX962NAMEDCURVETYPE
Pointer to an Aecparams structure see above
AIECParametersBER
AIECParametersBER
AIECParamGen
Pointer to a Becparamgenparams structure
Pointer to a Becparamgenparams structure see above
FieldType = FTF2ONB
Crypto-C procedures to use with algorithm object
AIECPubKey
Pointer to an Aecpublickey structure
Can get this info type if algorithm object already has
AIECPubKeyBER
Pointer to a structure of type Bblkcipherwfeedbackparams
AIFeedbackCipher
Descriptor for block ciphers with feedback, as defined
Type of padding schemes available
AIFeedbackCipher
2Algorithm methods for feedback modes
CFB modes require a Bcfbparams structure
Depends on cipher type, as follows
Compatible representations
Aihmac
Output considerations
Random bytes generated by your hardware device
Other procedures
AIHWRandom
Where Akeypairdefiner is defined by
AIKeypairTokenGen
Pointer to an Akeypairspecifier structure
Pointer to an Akeypairspecifier structure see above
Key-pair generation AM specified by cipherName
Aimac
Output of BDigestFinal will be 16 bytes long
Aimd
Message digest MD algorithm as defined by Bsafe
AIMD2
MD2 message digest algorithm as defined in RFC
Output considerations
AIMD2BER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 101
AIMD2PEM
A p t e r 2 a l g o r i t h m I n f o Ty p e s 103
AIMD2Random
Pointer to a Bpbeparams structure see above
AIMD2WithDESCBCPad
Pointer to a Bpbeparams structure
KIItem that gives the password
AIMD2WithDESCBCPadBER
AIMD2WithDESCBCPad
AIMD2WithRC2CBCPad
Pointer to a BRC2PBEPARAMS structure
Pointer to a BRC2PBEPARAMS structure see above
AIMD2WithRC2CBCPadBER
AIMD2WithRC2CBCPad
AIMD2WithRSAEncryption
KIRSAPublic, KIRSAPublicBER, or KIRSAPublicBSAFE1
AIMD2WithRSAEncryptionBER
AIMD2WithRSAEncryption
AIMD5
MD5 message digest algorithm as defined in RFC
AIMD5BER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 119
AIMD5PEM
A p t e r 2 a l g o r i t h m I n f o Ty p e s 121
AIMD5Random
MD5-Random algorithm for generating pseudo-random numbers
AIMD5WithDESCBCPad
AIMD5WithDESCBCPadBER
AIMD5WithDESCBCPadBER
AIMD5WithDESCBCPad
AIMD5WithRC2CBCPad
AIMD5WithRC2CBCPadBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 129
AIMD5WithRC2CBCPadBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 131
AIMD5WithRSAEncryption
A p t e r 2 a l g o r i t h m I n f o Ty p e s 133
AIMD5WithRSAEncryptionBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 135
AIMD5WithXOR
A p t e r 2 a l g o r i t h m I n f o Ty p e s 137
AIMD5WithXORBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 139
Pkcs Oaep RSA Parameter Default Value Default Params
AIPKCSOAEPRSAPrivate
Pointer to an Apkcsoaepparams structure
Format of info supplied to BGetAlgorithmInfo
A p t e r 2 a l g o r i t h m I n f o Ty p e s 143
AIPKCSOAEPRSAPrivateBER
Simple DER encoding for the default algorithm
General syntax is
Sequence
Following procedures perform Oaep padding with encryption
Pkcs Oaep RSA Parameter Default Value Default Parameters
AIPKCSOAEPRSAPublic
A p t e r 2 a l g o r i t h m I n f o Ty p e s 149
Amrsaencrypt
A p t e r 2 a l g o r i t h m I n f o Ty p e s 151
AIPKCSOAEPRSAPublicBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 153
Sequence
A p t e r 2 a l g o r i t h m I n f o Ty p e s 155
Input constraints
Either
Following parameters are employed when Nullptr is specified
AIPKCSOAEPRecode
Pointer to an Apkcsoaepparams structure
A p t e r 2 a l g o r i t h m I n f o Ty p e s 159
AIPKCSOAEPRecodeBER
AIPKCSOAEPRecodeBER
General syntax is
A p t e r 2 a l g o r i t h m I n f o Ty p e s 163
Format of info supplied to BGetAlgorithmInfo
A p t e r 2 a l g o r i t h m I n f o Ty p e s 165
AIPKCSRSAPrivate
A p t e r 2 a l g o r i t h m I n f o Ty p e s 167
AIPKCSRSAPrivateBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 169
AIPKCSRSAPrivatePEM
A p t e r 2 a l g o r i t h m I n f o Ty p e s 171
AIPKCSRSAPublic
Amrsaencrypt for encryption or Amrsadecrypt for decryption
A p t e r 2 a l g o r i t h m I n f o Ty p e s 173
AIPKCSRSAPublicBER
Amrsaencrypt for encryption and Amrsadecrypt for decryption
AIPKCSRSAPublicPEM
A p t e r 2 a l g o r i t h m I n f o Ty p e s 177
Pointer to an ARC2CBCPARAMS structure see above
AIRC2CBC
Pointer to an ARC2CBCPARAMS structure
When used with one of the should be used with
AIRC2CBCBSAFE1
A p t e r 2 a l g o r i t h m I n f o Ty p e s 181
AIRC2CBCPad
A p t e r 2 a l g o r i t h m I n f o Ty p e s 183
AIRC2CBCPadBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 185
AIRC2CBCPadPEM
A p t e r 2 a l g o r i t h m I n f o Ty p e s 187
AIRC4
RC4 encryption algorithm
AMRC4ENCRYPT for encryption and AMRC4DECRYPT for decryption
KIItem that gives the address and length of the RC4 key
A p t e r 2 a l g o r i t h m I n f o Ty p e s 189
AIRC4BER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 191
Pointer to a BRC4WITHMACPARAMS structure see above
AIRC4WithMAC
Pointer to a BRC4WITHMACPARAMS structure
A p t e r 2 a l g o r i t h m I n f o Ty p e s 193
AIRC4WithMACBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 195
Pointer to an ARC5CBCPARAMS structure see above
AIRC5CBC
Pointer to an ARC5CBCPARAMS structure
AIRC5CBC may be used to access the hardware-related Bhapi
KIItem, that gives the address and length of the RC5 key
AIRC5CBCPad
A p t e r 2 a l g o r i t h m I n f o Ty p e s 199
AIRC5CBCPadBER
KIItem, which gives the address and length of the RC5 key
Pointer to an ARC6CBCPARAMS structure see above
AIRC6CBC
Pointer to an ARC6CBCPARAMS structure
KIItem, that gives the address and length of the RC6 key
AIRC6CBCPad
Pointer to an ARC6CBCPARAMS structure
A p t e r 2 a l g o r i t h m I n f o Ty p e s 205
Airesetiv
Pointer to an Item
AIRFC1113Recode
AIRSAKeyGen
Pointer to an Arsakeygenparams structure
A p t e r 2 a l g o r i t h m I n f o Ty p e s 209
AIRSAPrivate
RSA algorithm for performing raw private-key encryption
AIRSAPrivate may include the hardware algorithm method
AIRSAPrivateBSAFE1
Integer at the beginning of the buffer
AIRSAPublic
RSA algorithm for performing raw public-key decryption
A p t e r 2 a l g o r i t h m I n f o Ty p e s 215
AIRSAPublicBSAFE1
A p t e r 2 a l g o r i t h m I n f o Ty p e s 217
AIRSAStrongKeyGen
A p t e r 2 a l g o r i t h m I n f o Ty p e s 219
For the randomAlgorithm argument in BDecryptUpdate
AISETOAEPRSAPrivate
Input considerations
AISETOAEPRSAPublic
A p t e r 2 a l g o r i t h m I n f o Ty p e s 223
AISHA1
Output of BDigestFinal will be 20 bytes long
AISHA1BER
AISHA1
AISHA1Random
AISHA1WithDESCBCPad
KIItem that gives the address and length of the password
AISHA1WithDESCBCPadBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 231
AISHA1WithRSAEncryption
A p t e r 2 a l g o r i t h m I n f o Ty p e s 233
AISHA1WithRSAEncryptionBER
A p t e r 2 a l g o r i t h m I n f o Ty p e s 235
Set the arguments for Bsignverifyparams as follows
AISignVerify
Pointer to a Bsignverifyparams structure
AX931PARAMS
Set the arguments for AX931PARAMS as follows
Pointer to a Bsignverifyparams structure see above
Key info types for keyObject in BSignInit or BVerifyInit
AISymKeyTokenGen
AISymKeyTokenGen
AIX931Random
Seed
Bsafe procedures to use with algorithm object
Pointer to an Asharandomparams structure
AIX962RandomV0
SHA1 pseudo-random generator as defined
Amsharandom
Key Info Types
1Sample Key Info Type
KI8Byte
Pointer to an unsigned char array that holds the 8 bytes
KI24Byte
Byte value for symmetric keys such as Desede
Pointer to an unsigned char array that holds the 24 bytes
KI24Byte, KIItem if the length of the Item is 24, Kidesx
KIDES8
KIDES8Strong
KIDES24Strong
KIDESBSAFE1
Bsafe 1.x encoding of a DES key
Kidesx
Pointer to an Adesxkey structure
KIDESXBSAFE1
Bsafe 1.x encoding of a Desx key
Pointer to an Adsaprivatekey structure
Where Adsaparams is defined as
KIDSAPrivate
KIDSAPrivate, KIDSAPrivateBER, or KIDSAPrivateX957BER
KIDSAPrivateBER
KIDSAPrivateX957BER
KIDSAPublic
Pointer to an Adsapublickey structure
KIDSAPublic, KIDSAPublicBER, KIDSAPublicX957BER
KIDSAPublicBER
KIDSAPublicX957BER
KIECPrivate
Pointer to an Aecprivatekey structure
KIECPrivateBER
KIECPrivateComponent
An elliptic curve private key without its curve parameters
KIECPrivateComponentBER
KIECPublic
KIECPublicBER
KIECPublicComponent
An elliptic curve public key without its curve parameters
KIECPublicComponentBER
Pointer to a Kiextendedtokeninfo structure
Where AX509ATTRIBINFO is defined by
KIExtendedToken
Pointer to a Kiextendedtokeninfo structure see above
Pointer to an Item structure see above
KIItem
Pointer to an Item structure
Akeypairdefiner is defined by
KIKeypairToken
Pointer to a Kikeypairtokeninfo structure
For
KIPKCSRSAPrivate
Pointer to an Apkcsrsaprivatekey structure
A p t e r 3 K e y I n f o Ty p e s 277
KIPKCSRSAPrivateBER
KIRC2BSAFE1
KIRC2WithBSAFE1Params
Kirsacrt
Pointer to an Arsacrtkey structure
KIRSAPrivate
Pointer to an Arsakey structure
A p t e r 3 K e y I n f o Ty p e s 283
KIRSAPrivateBSAFE1
Bsafe 1.x encoding of an RSA private key
KIRSAPublic
Arsakey
KIRSAPublicBER
KIRSAPublicBSAFE1
Bsafe 1.x encoding of an RSA public key
Pointer to a Kitokeninfo structure see above
KIToken
Pointer to a Kitokeninfo structure
Details of Crypto-C Functions
BBuildTableFinal
Int BBuildTableFinal
BBuildTableGetBufSize
Int BBuildTableGetBufSize
BBuildTableInit
BCreateAlgorithmObject
Int BCreateAlgorithmObject
BCreateKeyObject
Int BCreateKeyObject
BCreateSessionChooser
Int BCreateSessionChooser
BDecodeDigestInfo
Int BDecodeDigestInfo
BDecodeFinal
Int BDecodeFinal
BDecodeInit
Int BDecodeInit
BDecodeUpdate
Int BDecodeUpdate
BDecryptFinal
Int BDecryptFinal
BDecryptInit
BDecryptUpdate
Int BDecryptUpdate
There is no return value
Void BDestroyAlgorithmObject
BDestroyKeyObject
Void BDestroyKeyObject
BDigestFinal
Int BDigestFinal
BDigestInit
Int BDigestInit
BDigestUpdate
Int BDigestUpdate
BEncodeDigestInfo
Int BEncodeDigestInfo
BEncodeFinal
Int BEncodeFinal
BEncodeInit
Int BEncodeInit
BEncodeUpdate
Int BEncodeUpdate
BEncryptFinal
Int BEncryptFinal
BEncryptInit
BEncryptUpdate
Int BEncryptUpdate
BFreeSessionChooser
Int BFreeSessionChooser
BGenerateInit
BGenerateKeypair
Int BGenerateKeypair
BGenerateParameters
Int BGenerateParameters
BGenerateRandomBytes
Int BGenerateRandomBytes
BGetAlgorithmInfo
Int BGetAlgorithmInfo
BGetExtendedErrorInfo
Void BGetExtendedErrorInfo
BGetKeyExtendedErrorInfo
Void BGetKeyExtendedErrorInfo
BGetKeyInfo
Int BGetKeyInfo
BIntegerBits
BKeyAgreeInit
BKeyAgreePhase1
Int BKeyAgreePhase1
BKeyAgreePhase2
Int BKeyAgreePhase2
BRandomInit
Int BRandomInit
BRandomUpdate
Int BRandomUpdate
BSetAlgorithmInfo
Int BSetAlgorithmInfo
BSetKeyInfo
Int BSetKeyInfo
BSignFinal
BSignInit
Int BSignInit
BSignUpdate
BSymmetricKeyGenerate
Int BSymmetricKeyGenerate
Int BSymmetricKeyGenerateInit
BSymmetricKeyGenerateInit
Initializes key generation object
BVerifyFinal
Int BVerifyFinal
BVerifyInit
Int BVerifyInit
BVerifyUpdate
Int BVerifyUpdate
Tfree
Void Tfree
Tmalloc
Tmemcmp
Blocks are equal
Tmemcpy
Tmemmove
Void Tmemmove
Tmemset
Trealloc
Pointer Trealloc
Tstrcmp
Int Tstrcmp
Tstrcpy
Destination string
Tstrlen
Number of characters in the string
Tstrlen
Crypto-C Error Types
Crypto-C Error Types
P e n d i x a C r y p t o C Error Ty p e s 353
Page
UINT2 value is a 16-bit unsigned integer
Pointer
UINT2
UINT4
UINT4 value is a 32-bit unsigned integer Example
Otherwise Protolist should be defined as
Crypto-C defines one string constant Bsafeversion
Page
National Bureau of Standards. Fips Publication 46-1 Data
Operation. December
P1363 Draft D1
December
209
509
X9.31
X9.44 Draft
Index
AMMD2RANDOM
D e 363
Page
D e 365