Skip to Content
Secure Programming Cookbook for C and C++
book

Secure Programming Cookbook for C and C++

by John Viega, Matt Messier
July 2003
Intermediate to advanced
790 pages
23h 35m
English
O'Reilly Media, Inc.
Content preview from Secure Programming Cookbook for C and C++

4.9. Using Salts, Nonces, and Initialization Vectors

Problem

You want to use an algorithm that requires a salt, a nonce or an initialization vector (IV). You need to understand the differences among these three things and figure out how to select good specimens of each.

Solution

There’s a lot of terminology confusion, and the following Section 4.9.3 contains our take on it. Basically, salts and IVs should be random, and nonces are usually sequential, potentially with a random salt as a component, if there is room. With sequential nonces, you need to ensure that you never repeat a single {key, nonce} pairing.

To get good random values, use a well-seeded, cryptographically strong pseudo-random number generator (see the appropriate recipes in Chapter 11). Using that, get the necessary number of bits. For salt, 64 bits is sufficient. For an IV, get one of the requisite size.

Discussion

Salts, nonces, and IVs are all one-time values used in cryptography that don’t need to be secret, but still lead to additional security. It is generally assumed that these values are visible to attackers, even if it is sometimes possible to hide them. At the very least, the security of cryptographic algorithms and protocols should not depend on the secrecy of such values.

Tip

We try to be consistent with respect to this terminology in the book. However, in the real world, even among cryptographers there’s a lot of inconsistency. Therefore, be sure to follow the directions in the documentation for whatever primitive ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Secure Programming with C++

Secure Programming with C++

Howard Poston

Publisher Resources

ISBN: 0596003943Supplemental ContentErrata Page