Crypto-C
Cryptographic Components for C
Trademarks
License agreement
Distribution
Limit distribution of this document to trusted personnel
Contents
Quick Start
Cryptography
N t e n t s
Using Crypto-C 101
Algorithms in Crypto-C
Non-Cryptographic Operations 151
Saved State
Symmetric-Key Operations 177
Public-Key Operations 213
Secret Sharing Operations 305
Putting It All Together An X9.31 Example
Appendix a Command-Line Demos 327
Glossary 339 Index 349
List of Figures
A B S a F E C r y p t o C D e v e l o p e r ’s G u i d e
List of Tables
A B S a F E C r y p t o C D e v e l o p e r ’s G u i d e
Preface
What’s New in Version 5.2.2?
Improved performance
Hardware support
MultiPrime RSA
Organization of This Manual
Advanced Encryption Standard AES
Organization of This Manual
E f a c e
Conventions Used in This Manual
Crypto-C procedures to use with algorithm object
Conventions Used in This Manual
Terms and Abbreviations
Terms and Abbreviations
Related Documents
Related Documents
A B S a F E C r y p t o C D e v e l o p e r ’s G u i d e
Ieee Standard Specifications for Public-Key Cryptography on
Http//stdsbbs.ieee.org/groups/1363/index.html
How to Contact RSA Security
RSA Security Web Site Getting Support and Service
How to Contact RSA Security
You can get technical support as follows
Introduction
Crypto-C Toolkit
Algorithms
Public-Key Algorithms
Digital Signatures
Elliptic Curve Public-Key Algorithms
Secret Sharing
Cryptographic Standards and Crypto-C
Pkcs Standards and Crypto-C
Nist Standards and Crypto-C
Nist Approval and Windows 32-bit Platforms
Pkcs Compared with Nist
Nist Approval and Windows NT Platforms
Ansi X9 Standards and Crypto-C
Quick Start
Six-Step Sequence
Six-Step Sequence
Introductory Example
Include Files
Creating an Algorithm Object
Introductory Example
Where Pointer is defined in aglobal.h
Nullptr is also defined in aglobal.h
Typedef unsigned char *POINTER
#define Nullptr POINTER0
Balgorithmobj algorithmObject Algorithm object
Setting the Algorithm Object
Algorithm information
Init
Break
Creating a Key Object
Setting a Key Object
For our example, we use
Int BSetKeyInfo
Key information
Selecting an Algorithm Chooser
Now we can complete the call to BSetKeyInfo
Update
Saving the Object State optional
Surrender Context
We can now complete our call to BEncryptInit
Output data buffer
Unsigned int
Length of output data
Input data
For now, we declare
Unsigned int outputLenUpdate
Unsigned char *encryptedData = Nullptr
If status = BEncryptUpdate
Final
Destroy
Asurrenderctx *surrenderContext Surrender context
For our example, we use the following
Pointer to key object
Balgorithmobj * algorithmObject
Pointer block
Putting It All Together
For this example, call Tfree as follows
Tfree encryptedData
If rc4KeyItem.data != Nullptr
Init If status = BEncryptInit
Introductory Example
If encryptedData != Nullptr
EncryptedData = Nullptr End main
Decrypting the Introductory Example
Creating the Key Object
Decrypting the Introductory Example
First create the algorithm object
Setting the Key Object
Always destroy objects when you no longer need them
DecryptedData = Nullptr
Multiple Updates
Multiple Updates
Updatesize
Break End while
Multiple Updates
Summary of the Six Steps
Include
Create
Set
Final
Page
Cryptography
Cryptography Overview
Symmetric-Key Cryptography
Ciphers
Cryptography Overview
Block Ciphers
Padding
Ciphers in Crypto-C
Crypto-C implements the following block ciphers
Triple DES
2Triple DES Encryption as Implemented in Crypto-C
RC5
RC6
Modes of Operation
Four Modes
Electronic Codebook ECB Mode
3Electronic Codebook ECB Mode
Cipher Block Chaining CBC Mode
Cipher Feedback CFB Mode
5Cipher Feedback CFB Mode
Output Feedback OFB Mode
6Output Feedback Mode OFB
Stream Ciphers
Message Digests
RC4 algorithm with MAC
Message Digests and Pseudo-Random Numbers
Password-Based Encryption
Hash-Based Message Authentication Codes Hmac
8DES Key and IV Generation for Password Based Encryption
Public-Key Cryptography
RSA Algorithm
9Public-Key Cryptography
Modular Math
Prime Numbers
MultiPrime Numbers
RSA Algorithm
Cryptography Overview
Summary
Security
Calculation is shown in Table
1Calculation of 827 mod
Digital Envelopes
Optimal Asymmetric Encryption Padding Oaep
10Digital Envelope
Authentication and Digital Signatures
Cryptography Overview
11RSA Digital Signature
Digital Signature Algorithm DSA
Digital Certificates
Math
Diffie-Hellman Public Key Agreement
Algorithm
Phase
Phase
Parameter Generation
Math
Elliptic Curve Cryptography
Multiple-Party Key Agreement
Elliptic Curve Parameters
Finite Field
Fields of Even Characteristic
Odd Prime Fields
Coefficients Over an Odd Prime Field
= 0·I ≡ 2·2m-1·Imod2m
Coefficients Over a Field of Even Characteristic
Point P and its Order
Points of an Elliptic Curve
Elliptic curve parameters
Order of an Elliptic Curve
Order of a Point
Point of Prime Order
Is written EFq
Summary of Elliptic Curve Terminology
Cofactor
Order n of P Is sometimes called the base point
2Elliptic Curve Parameters
Representing Fields of Even Characteristic
Elliptic Curve Key Pair Generation
Creating the Key Pair
Ecdsa Signature Scheme
Signing a Message
Verifying a Signature
Math
Recall that Q = dP, so
Elliptic Curve Authenticated Encryption Scheme Ecaes
Now recall that s = k-1e+dr mod n, so
Encrypting a Message Using the Public Key
Decrypting a Message Using the Private Key
Elliptic Curve Diffie-Hellman Key Agreement
Phase
13Elliptic Curve Diffie-Hellman Key Agreement
Secret Sharing
First coordinate of S, xS, is their agreed-upon secret key
Working with Keys
Key Generation
Key Management
Key Escrow
Applications of Cryptography
Ascii Encoding and Decoding
Local Applications
Applications of Cryptography
Point-to-Point Applications
Client/Server Applications
Peer-to-Peer Applications
Choosing Algorithms
Public-Key vs. Symmetric-Key Cryptography
Stream vs. Block Symmetric-Key Algorithms
Choosing Algorithms
Block Symmetric-Key Algorithms
Key Agreement vs. Digital Envelopes
Secret Sharing and Key Escrow
Elliptic Curve Algorithms
Interoperability
Security Considerations
Handling Private Keys
Elliptic Curve Standards
Security Considerations
Temporary Buffers
Pseudo-Random Numbers and Seed Generation
Choosing Passwords
DES Weak Keys
Initialization Vectors and Salts
3DES Weak and Semi-Weak Keys
Stream Ciphers
Timing Attacks and Blinding
Pick a random value r and compute
= mre mod n
Choosing Key Sizes
MD5p padP MD5q padQ m
RSA Keys
4Summary of Recommended Key Sizes
Diffie-Hellman Parameters and DSA Keys
RC2 Effective Key Bits
RC4 Key Bits
RC5 Key Bits and Rounds
Elliptic Curve Keys
Using Crypto-C
Algorithms in Crypto-C
Information Formats Provided by Crypto-C
Basic Algorithm Info Types
BER-Based Algorithm Info Types
Algorithms in Crypto-C
Summary of AIs
PEM-Based Algorithm Info Types
BSAFE1 Algorithm Info Types
1Message Digests
Algorithms in Crypto-C 2Message Authentication
3ASCII Encoding
4Pseudo-Random Number Generation
5Symmetric Stream Ciphers
Algorithms in Crypto-C 5Symmetric Stream Ciphers
6Symmetric Block Ciphers
Algorithms in Crypto-C 6Symmetric Block Ciphers
RC2
7RSA Public-Key Cryptography
Key Generation
Algorithms in Crypto-C 7RSA Public-Key Cryptography
Oaep
8DSA Public-Key Cryptography
Digital Signatures
Algorithms in Crypto-C 9Diffie-Hellman Key Agreement
10Elliptic Curve Public-Key Cryptography
11Bloom-Shamir Secret Sharing
10 Elliptic Curve Public-Key Cryptography
12Hardware Interface
Algorithms in Crypto-C 13Advanced Encryption Standard AES
Algorithm Info Type
Keys In Crypto-C
Summary of KIs
Keys In Crypto-C
15Block Cipher Keys
16RSA Public and Private Keys
Keys In Crypto-C 15Block Cipher Keys
17DSA Public and Private Keys
Keys In Crypto-C 18Elliptic Curve Keys
System Considerations In Crypto-C
Algorithm Choosers
An Encryption Algorithm Chooser
System Considerations In Crypto-C
An RSA Algorithm Chooser
Surrender Context
Description of AIX962RandomV0 instead of AISHA1Random
Sample Surrender Function
Also gives the form that a surrender function must have
Reserved for future use
Int *Surrender Pointer handle
Saving State
When to Allocate Memory
Memory-Management Routines
Memory-Management Routines and Standard C Libraries
Crypto-C uses the following memory-management routines
Tmalloc Trealloc Tfree Tmemset Tmemcpy Tmemmove Tmemcmp
Memory Allocation
BER/DER Encoding
Binary Data
Typedef struct unsigned char *data unsigned int len
System Considerations In Crypto-C
Input and Output
Symmetric Block Algorithms
Input constraints
Output considerations
20Input Limits for RSA Pkcs Encryption
General Considerations
Specifying User Keys
Using Bdemo
Sign a File
Verify a Signed File
Create a File Envelope
Open a File Envelope
Generate a Key Pair
Running Bdemodsa
Using Bdemodsa
Enter any arbitrary string of printable characters
Sign a File
Using Bdemoec
Running Bdemoec
File Reference
File Reference
Table A-1Demo Program Source Files
BSLite
BSLite Table A-1Demo Program Source Files
BSLite
Page
Glossary
Advanced Encryption Standard
Series of steps used to complete a task
American National Standards Institute
Application Programming Interface
O s s a r y
Generic security service application program interface
Electronic business Data Interchange
See ECC
See XOR
Process of having a third party hold onto encryption keys
Process that creates a larger key from the original key
Act of creating a key
An algorithm that generates the subkeys in a block cipher
Data to be encrypted
Extra bits concatenated with a key, password, or plaintext
Private key in the RSA public-key cryptosystem
Number extracted from a pseudo- random sequence
Secure Multipurpose Internet Mail Extensions
Simple Mail Transfer Protocol
Secure Wide Area Network
See secret key
Trusted Computer System Evaluation Criteria
XOR
Page
Index
Ecdsa
D e
A B S a F E C r y p t o C D e v e l o p e r ’s G u i d e
D e
See also RC4 subprime