Cryptographic Components for C
Crypto-C
Limit distribution of this document to trusted personnel
Trademarks
License agreement
Distribution
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
MultiPrime RSA
What’s New in Version 5.2.2?
Improved performance
Hardware support
E f a c e
Organization of This Manual
Advanced Encryption Standard AES
Organization of This Manual
Crypto-C procedures to use with algorithm object
Conventions Used in This Manual
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
You can get technical support as follows
How to Contact RSA Security
RSA Security Web Site Getting Support and Service
How to Contact RSA Security
Introduction
Algorithms
Crypto-C Toolkit
Secret Sharing
Public-Key Algorithms
Digital Signatures
Elliptic Curve Public-Key Algorithms
Nist Approval and Windows 32-bit Platforms
Cryptographic Standards and Crypto-C
Pkcs Standards and Crypto-C
Nist Standards and Crypto-C
Nist Approval and Windows NT Platforms
Pkcs Compared with Nist
Ansi X9 Standards and Crypto-C
Quick Start
Six-Step Sequence
Six-Step Sequence
Introductory Example
Introductory Example
Include Files
Creating an Algorithm Object
#define Nullptr POINTER0
Where Pointer is defined in aglobal.h
Nullptr is also defined in aglobal.h
Typedef unsigned char *POINTER
Setting the Algorithm Object
Balgorithmobj algorithmObject Algorithm object
Algorithm information
Break
Init
Setting a Key Object
Creating a Key Object
For our example, we use
Key information
Int BSetKeyInfo
Now we can complete the call to BSetKeyInfo
Selecting an Algorithm Chooser
We can now complete our call to BEncryptInit
Update
Saving the Object State optional
Surrender Context
Input data
Output data buffer
Unsigned int
Length of output data
Unsigned int outputLenUpdate
For now, we declare
Unsigned char *encryptedData = Nullptr
Final
If status = BEncryptUpdate
Asurrenderctx *surrenderContext Surrender context
Destroy
Pointer block
For our example, we use the following
Pointer to key object
Balgorithmobj * algorithmObject
If rc4KeyItem.data != Nullptr
Putting It All Together
For this example, call Tfree as follows
Tfree encryptedData
Init If status = BEncryptInit
Introductory Example
EncryptedData = Nullptr End main
If encryptedData != Nullptr
First create the algorithm object
Decrypting the Introductory Example
Creating the Key Object
Decrypting the Introductory Example
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
Set
Summary of the Six Steps
Include
Create
Final
Page
Cryptography
Cryptography Overview
Cryptography Overview
Symmetric-Key Cryptography
Ciphers
Crypto-C implements the following block ciphers
Block Ciphers
Padding
Ciphers in Crypto-C
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
RSA Algorithm
Modular Math
Prime Numbers
MultiPrime Numbers
Cryptography Overview
1Calculation of 827 mod
Summary
Security
Calculation is shown in Table
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
Elliptic curve parameters
Coefficients Over a Field of Even Characteristic
Point P and its Order
Points of an Elliptic Curve
Is written EFq
Order of an Elliptic Curve
Order of a Point
Point of Prime Order
2Elliptic Curve Parameters
Summary of Elliptic Curve Terminology
Cofactor
Order n of P Is sometimes called the base point
Elliptic Curve Key Pair Generation
Representing Fields of Even Characteristic
Ecdsa Signature Scheme
Creating the Key Pair
Signing a Message
Math
Verifying a Signature
Elliptic Curve Authenticated Encryption Scheme Ecaes
Recall that Q = dP, so
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
Applications of Cryptography
Applications of Cryptography
Ascii Encoding and Decoding
Local Applications
Point-to-Point Applications
Client/Server Applications
Peer-to-Peer Applications
Choosing Algorithms
Choosing Algorithms
Public-Key vs. Symmetric-Key Cryptography
Stream vs. Block Symmetric-Key Algorithms
Key Agreement vs. Digital Envelopes
Block Symmetric-Key Algorithms
Elliptic Curve Algorithms
Secret Sharing and Key Escrow
Interoperability
Security Considerations
Security Considerations
Handling Private Keys
Elliptic Curve Standards
Pseudo-Random Numbers and Seed Generation
Temporary Buffers
Choosing Passwords
Initialization Vectors and Salts
DES Weak Keys
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
RC5 Key Bits and Rounds
Diffie-Hellman Parameters and DSA Keys
RC2 Effective Key Bits
RC4 Key Bits
Elliptic Curve Keys
Algorithms in Crypto-C
Using Crypto-C
Algorithms in Crypto-C
Information Formats Provided by Crypto-C
Basic Algorithm Info Types
BER-Based Algorithm Info Types
1Message Digests
Summary of AIs
PEM-Based Algorithm Info Types
BSAFE1 Algorithm Info Types
5Symmetric Stream Ciphers
Algorithms in Crypto-C 2Message Authentication
3ASCII Encoding
4Pseudo-Random Number Generation
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
10 Elliptic Curve Public-Key Cryptography
11Bloom-Shamir Secret Sharing
12Hardware Interface
Algorithm Info Type
Algorithms in Crypto-C 13Advanced Encryption Standard AES
15Block Cipher Keys
Keys In Crypto-C
Summary of KIs
Keys In Crypto-C
Keys In Crypto-C 15Block Cipher Keys
16RSA Public and Private Keys
17DSA Public and Private Keys
Keys In Crypto-C 18Elliptic Curve Keys
System Considerations In Crypto-C
System Considerations In Crypto-C
Algorithm Choosers
An Encryption Algorithm Chooser
An RSA Algorithm Chooser
Description of AIX962RandomV0 instead of AISHA1Random
Surrender Context
Int *Surrender Pointer handle
Sample Surrender Function
Also gives the form that a surrender function must have
Reserved for future use
Saving State
When to Allocate Memory
Tmalloc Trealloc Tfree Tmemset Tmemcpy Tmemmove Tmemcmp
Memory-Management Routines
Memory-Management Routines and Standard C Libraries
Crypto-C uses the following memory-management routines
BER/DER Encoding
Memory Allocation
Binary Data
Typedef struct unsigned char *data unsigned int len
System Considerations In Crypto-C
Output considerations
Input and Output
Symmetric Block Algorithms
Input constraints
20Input Limits for RSA Pkcs Encryption
General Considerations
Using Bdemo
Specifying User Keys
Sign a File
Create a File Envelope
Verify a Signed File
Open a File Envelope
Generate a Key Pair
Using Bdemodsa
Running 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
Application Programming Interface
Advanced Encryption Standard
Series of steps used to complete a task
American National Standards Institute
O s s a r y
See XOR
Generic security service application program interface
Electronic business Data Interchange
See ECC
An algorithm that generates the subkeys in a block cipher
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
Extra bits concatenated with a key, password, or plaintext
Data to be encrypted
Private key in the RSA public-key cryptosystem
Secure Multipurpose Internet Mail Extensions
Number extracted from a pseudo- random sequence
Trusted Computer System Evaluation Criteria
Simple Mail Transfer Protocol
Secure Wide Area Network
See secret key
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