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