Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SM2 #105

Open
wants to merge 7,300 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7300 commits
Select commit Hold shift + click to select a range
2d6a7a0
There are cases where a program doing dns requests wants to set the
Jan 14, 2019
0719461
For all functions known to be infected by LC_NUMERIC, add short
Jan 16, 2019
a85cc0f
Add a direct copy of the exension parsing code to be modified for tls13.
Jan 17, 2019
10ebba3
Add support to enforce restrictions on where extensions can appear
Jan 17, 2019
0e13db9
Provide an extensible buffer implementation that uses a read callback.
Jan 17, 2019
bd236a1
Get rid of is_serverhello in preparation for other messages
Jan 17, 2019
2a3ca09
Add regress for extensible buffer code.
Jan 17, 2019
3696530
Rename TLS extension handling to use less "hello".
Jan 18, 2019
ae14fe7
Update regress following TLS extension renaming.
Jan 18, 2019
e94fa82
Add support for RFC 8446 section 4.2 enforcing which extensions may
Jan 18, 2019
7706ea1
Remove this copy, we have decided we can do this in place
Jan 18, 2019
0bd17d3
Change the default digest type to sha256, and add support for
Jan 18, 2019
fe8a0b7
Add the -iter and -pbkdf2 argumenst to enc
Jan 18, 2019
0f6b545
Removed unused struct members.
Jan 18, 2019
7d0d268
Expose some symbols in a new tls13_handshake.h for regression testing.
Jan 18, 2019
b7dd37e
tweak previous;
Jan 18, 2019
0e100c7
Replace the vague, incorrect, and confusing BUGS sections with CAVEATS
Jan 18, 2019
17fadd1
Improve the description of locale dependency:
Jan 18, 2019
49f6109
Add client side of supported versions and keyshare extensions with ba…
Jan 18, 2019
5f8a35e
bump copyright years appopriately
Jan 18, 2019
32e4f3b
copyright
Jan 18, 2019
c2a30a4
initialize offset value so this passes
Jan 18, 2019
688941e
Add -iter and -pbkdf2 to the usage synopsis.
Jan 18, 2019
5d908f5
switch the default algorithm for the dgst command from MD5 to SHA256
Jan 18, 2019
ab3da4c
Partial port of EC_KEY_METHOD from OpenSSL 1.1.
Jan 19, 2019
00a0a3b
Partial port of EC_KEY_METHOD from OpenSSL 1.1.
Jan 19, 2019
7fcf73a
Partial port of EC_KEY_METHOD from OpenSSL 1.1.
Jan 19, 2019
9d69781
$OpenBSD$
Jan 19, 2019
c7ca990
provide EVP_ENCODE_CTX_{new,free}().
Jan 19, 2019
5dbf555
bump minors after symbol addition
Jan 19, 2019
b66c667
Provide a TLS record handling implementation.
Jan 19, 2019
36d6089
Add regress for TLSv1.3 record handling.
Jan 19, 2019
67a4487
Hook record regress.
Jan 19, 2019
6e6da3e
Tweak return value handling in the TLSv1.3 handshake code.
Jan 19, 2019
c52c253
Add handshake message type checking and special case certificate requ…
Jan 19, 2019
ce8330b
Sort HDRS/SRCS lists and use one line per source file for maintainabi…
Jan 19, 2019
6376488
In evp.h rev. 1.71, tb@ added EVP_ENCODE_CTX_new(3) and
Jan 19, 2019
96f5888
spelling;
Jan 19, 2019
bd9a17b
change the default digest used by
Jan 19, 2019
368822c
Fix BN_is_prime_* calls in libcrypto, the API returns -1 on error.
Jan 20, 2019
785f7ec
Fix BN_is_prime_* calls in openssl(1), the API returns -1 on error.
Jan 20, 2019
b20b2bf
Add an explicit flag to indicate a successful handshake instead
Jan 20, 2019
dc02e89
TLS 1.3 clients always need to send the supported groups extension.
Jan 20, 2019
e8b79c2
Add some internal consistency checks to the handshake state handling.
Jan 20, 2019
e209440
include stdint.h over sys/types.h
Jan 20, 2019
b350d57
Add missing prototype for tls13_handshake_active_action().
Jan 20, 2019
b98afbf
revert second hunk of previous that was committed by accident
Jan 20, 2019
91c51d4
Add a simple test that verifies that every valid handshake
Jan 20, 2019
fbc1de3
hook handshake test
Jan 20, 2019
9a279ba
Provide a way to get just the record header.
Jan 20, 2019
512cb1a
Update record regress to match functionality changes.
Jan 20, 2019
9e78dfb
Provide an initial implementation of the TLS 1.3 record layer.
Jan 20, 2019
058c511
Provide a handshake message handling implementation for TLS 1.3.
Jan 20, 2019
958c158
Fix header guard
Jan 20, 2019
1d3f141
Store the record version and make it available for use.
Jan 21, 2019
2162717
Teach ssl_version_string() about TLS1_3_VERSION.
Jan 21, 2019
286e1f7
Ensure we free TLS 1.3 handshake state.
Jan 21, 2019
90ba0b3
Move struct tls13_ctx into a header since other things need access to…
Jan 21, 2019
914afc7
Provide TLS 1.3 cipher AEAD/hash and legacy I/O handling functions.
Jan 21, 2019
5aaa9e1
Correct some rwstate handling that I broke when refactoring.
Jan 21, 2019
0360811
Add ssl_cipher_is_permitted(), an internal helper function that
Jan 21, 2019
c868ac5
Use ssl_cipher_is_permitted() in ssl_cipher_list_to_bytes().
Jan 21, 2019
2ed91c0
The main handshake loop can be shared between client and server.
Jan 21, 2019
ab6a9c1
In ssl_lib.c rev. 1.197, jsing@ added TLSv1.3 support to SSL_get_vers…
Jan 21, 2019
85544a8
Wire up the handshake message send and recv actions.
Jan 21, 2019
b49b965
Provide the initial TLSv1.3 client implementation.
Jan 21, 2019
36ef2e2
Move ssl_cipher_list_to_bytes() and ssl_bytes_to_cipher_list() to
Jan 21, 2019
8d3ceb0
Use the actual handshake message type in the certificate request hand…
Jan 21, 2019
506559c
Add example showing a proper comparison function, as many examples show
Jan 21, 2019
30152d1
a few tweaks
Jan 21, 2019
1450233
lenght -> length
Jan 21, 2019
f9ad715
add support for xchacha20 and xchacha20-poly1305
Jan 22, 2019
64b7cd7
Add missing symbols from the EC_KEY_METHOD port.
Jan 22, 2019
9db79bc
Provide SSL_get_client_ciphers().
Jan 22, 2019
62b11ba
Add a re-implementation of SSL_get1_supported_ciphers().
Jan 22, 2019
0c34d92
Document SSL_get1_supported_ciphers(3) and SSL_get_client_ciphers(3).
Jan 22, 2019
fd27832
bump minors after symbol addition
Jan 22, 2019
e7bf81e
Wrap long line
Jan 22, 2019
ca2c7fa
sort sections, and add a missing verb to the EXAMPLES text;
Jan 22, 2019
8af4094
No need to include <bsd.prog.mk> here.
Jan 23, 2019
d989ef1
Remove static from handshakes[][] so it is visible from regress/
Jan 23, 2019
e5ec927
Add a regression test that builds up the handshake state table
Jan 23, 2019
4f46436
do not print the command in the print: target
Jan 23, 2019
153200a
incorrrect spelling
Jan 23, 2019
6400bb1
Sync the handshakes table with the generated table in regress.
Jan 23, 2019
84eb749
Modify sigalgs extension processing for TLS 1.3.
Jan 23, 2019
89ff437
revert previous, accidentally contained another diff in addition
Jan 23, 2019
ca7d349
Modify sigalgs extension processing to accomodate TLS 1.3.
Jan 23, 2019
ef965ee
assert.h is often misused. It should not be used in a library
Jan 23, 2019
586df12
Rename NUM_HANDSHAKE to handshake_count and make it a variable
Jan 23, 2019
f8774e7
make whitespace inside curlies consistent; sort function prototypes.
Jan 23, 2019
144901a
Correct ECDSA_SECP512R1 typo to ECDSA_SECP521R1
Jan 23, 2019
19d8f54
Remove SHA224 based sigalgs from use in TLS 1.2 as SHA224 is deprecated.
Jan 24, 2019
a191222
move the extensions_seen into the handshake struct
Jan 24, 2019
a645a66
Add server side of versions, keyshare, and client and server of cookie
Jan 24, 2019
a063aaa
set the NEGOTIATED flag in the flags argument rather than
Jan 24, 2019
5207b03
Set pointer variables in tls13 handshake to NULL on clear
Jan 24, 2019
6e74154
Add code to visualize the state machine. Both the state machine and the
Jan 24, 2019
f13ce05
I am retiring my old email address; replace it with my OpenBSD one.
Jan 25, 2019
ca361ed
sort output suffixes
Jan 25, 2019
7a0cccf
print errors to stderr
Jan 25, 2019
19a8bdc
Recent discussions about abort() potentially leaving key material in
Jan 26, 2019
a77ee7f
refactor and clean up the code generating dot output.
Jan 27, 2019
b925f98
zap a commented out line. 0RTT will need more thought than
Jan 27, 2019
9815416
Add tls_extension_seen(), a utility to know if a particular extension
Jan 28, 2019
f4605c8
Deduplicate a bunch of replicated code in the extension handling
Jan 28, 2019
de45392
spelling;
Jan 28, 2019
033f890
Remove SSLv23 padding mode from rsautl's usage (left behind in a removal
Jan 29, 2019
0d9f391
instead of calling abort() for 3 "must not use anymore" interfaces,
Jan 29, 2019
3414be8
Correct handling of TLS sigalgs extension for TLSv1.0/TLSv1.1.
Jan 30, 2019
83cff9c
unwrap a line introduced in previous.
Jan 31, 2019
83d40b4
Use malloc() and memcpy() the test X25519 x25519_peer_public value.
Feb 3, 2019
5fd2444
Revert r1.38 as it introduces use of a stack value post function return.
Feb 3, 2019
705073e
Convert openssl(1) rsautl to the newer style of option handling.
Feb 3, 2019
5b6c948
zap spaces before tabs
Feb 3, 2019
28e74a5
Document missing command line options for the rsautl command.
Feb 4, 2019
8f429c7
Make it easier to build with LIBRESSL_HAS_TLS1_3 enabled.
Feb 4, 2019
1852e01
Implement parsing and processing of TLSv1.3 ServerHello messages.
Feb 4, 2019
3a35d23
Convert openssl(1) pkey to the newer style of option handling.
Feb 5, 2019
4128944
Add islower check to show_ciphers in pkey.c and rsa.c.
Feb 5, 2019
11272d3
Implement processing of EncryptedExtensions in the TLS 1.3 client.
Feb 7, 2019
386385a
Summarize the 4 same name functions and move it to apps.c
Feb 9, 2019
c1fe277
Provide a reference from the TLSv1.3 context to the handshake state.
Feb 9, 2019
68e82be
Rename tls1_handshake_hash*() to tls1_transcript_hash*().
Feb 9, 2019
3215287
Rename the file that contains the transcript handling code.
Feb 9, 2019
300bcea
Fix weird wrap showing cipher list in interactive mode
Feb 9, 2019
7da486c
Preserve the transcript hash at specific stages of the TLSv1.3 handsh…
Feb 10, 2019
1e6ee23
"non-existant" is one of those words that don't exist, so use "non-ex…
Feb 10, 2019
b95e151
getopt(3) returns int, not char. Fix type of ch variable to prevent
Feb 11, 2019
84603b6
Implement handling of Certificate and CertificateVerify messages.
Feb 11, 2019
7401a70
Xr the byteorder funcs; from tim kuijsten
Feb 13, 2019
b823278
New futex(2) based rwlock implementation based on the mutex code.
Feb 13, 2019
4d26f56
Handle finished messages in TLSv1.3 client.
Feb 13, 2019
8ad7f65
Clean up some pesky trailing whitespace.
Feb 13, 2019
80ffe95
one more error message that should go to stderr
Feb 13, 2019
59559dd
Provide a TLS 1.3 capable client method.
Feb 14, 2019
d34983d
Split tls13_record_layer_set_traffic_keys() into two separate functions.
Feb 14, 2019
bfbd5f8
Switch to application traffic keys as appropriate.
Feb 14, 2019
2035cec
Notify the record layer upon handshake completion.
Feb 14, 2019
53d4882
Correct guards.
Feb 14, 2019
99e7321
Add tests for pkeyutl
Feb 16, 2019
e78e597
Convert openssl(1) pkeyutl to the newer style of option handling.
Feb 17, 2019
58398b7
Fix a few cases where int was used instead of ssize_t.
Feb 21, 2019
4f66e30
Change the alert callback return type from int to void.
Feb 21, 2019
85c681d
Wire up alert handling for TLSv1.3.
Feb 21, 2019
822480e
Test that all supported TLS ciphers actually work. Establish
Feb 21, 2019
a8bf930
Set BIO retry on TLS13_IO_WANT_POLLIN/TLS13_IO_WANT_POLLOUT.
Feb 23, 2019
26ceb3b
Remove temporary gotos.
Feb 23, 2019
73a373d
Move struct ssl_handshake_tls13_st definition
Feb 25, 2019
d32167e
Correct a few error returns.
Feb 25, 2019
bd92cd1
Add a handshake action sent handler and use it for client finished.
Feb 25, 2019
edd674e
Correctly handle oversize writes.
Feb 25, 2019
60074e6
revert "Move struct ssl_handshake_tls13_st definition", i.e., move
Feb 25, 2019
b685e6d
Fix gcc3 compilation error by using a forward declaration instead of a
Feb 25, 2019
30ee6c1
Correctly handle tls_read() and tls_write() failures.
Feb 26, 2019
e0c3a80
Correctly propagate EOF from BIO in tls13_legacy_wire_read().
Feb 26, 2019
cf69c0d
Correct return values for non-fatal alerts.
Feb 26, 2019
e45909c
Remove unused record_type from TLSv1.3 handshake actions.
Feb 28, 2019
18f485e
Add appropriate length checks to tls13_legacy_{read,write}_bytes()
Feb 28, 2019
c8da83e
Set the SSL state as part of tls13_legacy_connect().
Feb 28, 2019
37422e1
Automatically complete the handshake from tls13_legacy_{read,write}_b…
Feb 28, 2019
d5ab100
Implement non-SSL_MODE_ENABLE_PARTIAL_WRITE in tls13_legacy_write_byt…
Feb 28, 2019
a0b7c21
Fix OID for sm3WithRSAEncryption which was apparently mixed up
Mar 2, 2019
c1c54cb
Don't index a void pointer, fixes compilation with visual studio.
Mar 4, 2019
d435010
Typo in comment.
Mar 6, 2019
a0ce283
delete functions from the manual page that do nothing in LibreSSL
Mar 10, 2019
1fb71a2
rename CRYPTO_set_locking_callback.3 to CRYPTO_lock.3
Mar 10, 2019
ac7d640
fix some cases of spaces before full stops, where none were neccessary;
Mar 10, 2019
4a6d6f0
Backport support for probing ARMv8 HW acceleration capabilities on armv7
Mar 13, 2019
125ff65
add a comment to format-pem.pl documenting typical steps to update
Mar 13, 2019
765776d
Fix a number of ASN1_INTEGER vs ASN1_STRING mixups coming from the
Mar 13, 2019
e344b52
Document OCSP_basic_verify(3).
Mar 15, 2019
dde2f95
OpenSSL documents the macro OPENSSL_VERSION_TEXT since Sep 24, 2018;
Mar 15, 2019
4288eaf
Document the return values of X509_delete_ext(3) and X509_add_ext(3).
Mar 15, 2019
0c88aa9
Remove the alert level from the TLSv1.3 alert callback.
Mar 17, 2019
2dc8254
Partially clean up the TLS1_get_{,client}_version macros.
Mar 17, 2019
5a1708d
Correct return value handling in tls13_handshake_recv_action().
Mar 17, 2019
ff8fdf5
Provide version agnostic DTLS methods.
Mar 17, 2019
7aabbf6
Add the SM4 block cipher from the Chinese standard GB/T 32907-2016.
Mar 17, 2019
0c4736e
Add the SM4 block cipher from the Chinese standard GB/T 32907-2016.
Mar 17, 2019
b12e8e6
Add a regress test for the SM4 block cipher from the Chinese standard
Mar 17, 2019
b89df50
link sm4 regress to the build
Mar 17, 2019
bcfb7dc
Provide EVP_aes_{128,192,256}_wrap(). This is a compatible
Mar 17, 2019
83ba0e5
Provide EVP_PKEY_get0_hmac(). From OpenSSL 1.1.1 which is still
Mar 17, 2019
7457086
bump minors after symbol addition
Mar 17, 2019
85daf5d
Add regress tests for the EVP_aes_*_wrap() API. Based on the tests in
Mar 17, 2019
17bc27a
In evp.h rev. 1.75, tb@ provided EVP_PKEY_get0_hmac(3).
Mar 18, 2019
37b127a
Expand the ERR_PACK() macro to ERR_REASON() for consistency.
Mar 18, 2019
428d592
Document SM4; related to evp.h rev. 1.73.
Mar 18, 2019
31e429b
In ssl.h rev. 1.165, tb@ provided version agnostic DTLS methods.
Mar 18, 2019
fe45cac
Split EVP_aes_128_cbc(3) out of EVP_EncryptInit(3):
Mar 18, 2019
afb24d0
Insert a missing input line break after a .Vt macro;
Mar 18, 2019
7fddb24
* note that the handshake must be completed first
Mar 18, 2019
2b1a812
Revert TLS1_get{,_client}_version simplification because DTLS.
Mar 19, 2019
5205d95
Avoid an internal 2 byte overread in ssl_sigalgs().
Mar 19, 2019
b4cfdb0
Document the flag EVP_CIPHER_CTX_FLAG_WRAP_ALLOW needed for the EVP
Mar 19, 2019
90a3e19
escape backslashes;
Mar 20, 2019
e9d1b1c
fix examples (libtls uses its own error reporting mechanism)
Mar 20, 2019
0321834
Bring back EVP_chacha20 list item that was accidentally removed
Mar 21, 2019
f2875a6
add a handful of missing functions
Mar 21, 2019
4fd2460
Split EVP_des_cbc(3) out of EVP_EncryptInit(3) to reduce clutter:
Mar 21, 2019
948bb04
Split EVP_rc4(3) out of EVP_EncryptInit(3) to reduce clutter.
Mar 21, 2019
304c978
space before punct;
Mar 21, 2019
fc5bca5
import EVP_camellia_128_cbc(3) from OpenSSL 1.1.1,
Mar 21, 2019
948dfc3
Fix typo in usage and comment.
Mar 21, 2019
136e6c9
Add range checks to varios ASN1_INTEGER functions to ensure the
Mar 23, 2019
011acc9
do not call assert(), which has a tendency to leave traces of stuff in
Mar 24, 2019
14295ae
Cast nonce bytes to avoid undefined behaviour when left shifting.
Mar 24, 2019
d881b9d
Don't allow asn1_parse2 to recurse arbitrarily deep. Constrain to a max
Mar 24, 2019
92ed1f7
If ssl_cipher_apply_rule() is given a specific cipher suite, match on…
Mar 24, 2019
6df7b19
In the incredibly unbelievable circumstance where _rs_init() fails to
Mar 24, 2019
972ac56
Add a chain member to CERT_PKEY and provide functions for manipulatin…
Mar 25, 2019
ae30d81
Rework ssl3_output_cert_chain() to take a CERT_PKEY and consider chains.
Mar 25, 2019
aff457c
Remove ssl_get_server_send_cert() which is now unused.
Mar 25, 2019
6c29f61
Rework ssl_ctx_use_certificate_chain_bio() to use the CERT_PKEY chain.
Mar 25, 2019
34d162d
Defer sigalgs selection until the certificate is known.
Mar 25, 2019
11360af
tls1_process_sigalgs() is no longer needed.
Mar 25, 2019
3afc854
Strip out all of the pkey to sigalg and sigalg to pkey linkages.
Mar 25, 2019
2f67ae4
Update regress following sigalgs changes.
Mar 25, 2019
ab25976
Use limits.h instead of sys/limits.h for portability.
Mar 26, 2019
0ed7d61
Some first attempt adding sm2
ni4 Mar 6, 2019
51eaedc
Fix sm2_asn1_meth definition.
ni4 Mar 7, 2019
14baa94
Include ecdsa.h for ECDSA_SIG
ni4 Mar 7, 2019
b078918
Add error codes and some other header updates, make error definitions…
ni4 Mar 7, 2019
c05b685
Expand ASN.1 macroses.
ni4 Mar 8, 2019
5376b73
Fix outdated openssl calls.
ni4 Mar 15, 2019
ababa60
Fix coding style and warning about unititalized variables.
ni4 Mar 15, 2019
9ee5a1e
More fixes for build errors.
ni4 Mar 15, 2019
ca3e7e0
Add SM2_kdf function instead of not used in libressl ECDH_KDF_X9_62.
ni4 Mar 16, 2019
67e2777
Update sm2 tests to work and match libressl SSL.
ni4 Mar 19, 2019
9d6e947
Remove random faking from tests since it doesn't seem to be available…
ni4 Mar 19, 2019
b790c6e
Update with changes from add-sm2 branch (sm2-ecies, etc).
ni4 Mar 19, 2019
b3d4a37
Move some of sm2 functions to the local header.
ni4 Mar 19, 2019
461863b
Check function results and report errors.
ni4 Mar 20, 2019
92418aa
Check for possible errors in SM2_ciphertext_size/SM2_plaintext_size.
ni4 Mar 21, 2019
885780b
Add EVP_PKEY_set_alias_type function.
ni4 Mar 20, 2019
c4c51b0
Move sm2 algorithms to sm2-specific evp method.
ni4 Mar 21, 2019
0df398d
Add sm2evptest.
ni4 Mar 21, 2019
48bac92
Add uid field support for SM2
ni4 Mar 22, 2019
74b93a3
SM2: add signature verification test and extend test with uid field s…
ni4 Mar 22, 2019
ba1ec92
Fix return result of sm2_sign function.
ni4 Mar 22, 2019
417a86a
Update sm2evptest with per-line checks and some output.
ni4 Mar 22, 2019
a47f103
Fix warning about BN_mod_inverse and use constant-time function version.
ni4 Mar 24, 2019
9417009
Update manuals with sm2-related functions.
ni4 Mar 25, 2019
87a233e
Add missing sm2_pmeth.c to the Makefile
ni4 Apr 2, 2019
5fa39e2
Correct ciphertext size calculation and simplify field size calculation.
ni4 Apr 2, 2019
43bed1c
Remove sm2 tests code which used fake RNG
ni4 Apr 4, 2019
c7e40cd
Revert breaking changes to the digest.c.
ni4 Apr 4, 2019
61e2186
Replace double EVP_DigestSignInit/EVP_DigestVerify init calls for SM2…
ni4 Apr 4, 2019
9139cd9
Use buffer instead of string for uid in sm2 signature scheme.
ni4 Apr 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
16 changes: 5 additions & 11 deletions src/lib/libc/crypt/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# $OpenBSD: Makefile.inc,v 1.13 1999/11/17 05:22:36 millert Exp $
# $OpenBSD: Makefile.inc,v 1.27 2016/03/30 06:38:41 jmc Exp $

.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/crypt ${LIBCSRCDIR}/crypt
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/crypt ${LIBCSRCDIR}/crypt

SRCS+= cast.c crypt.c morecrypt.c md5crypt.c arc4random.c blowfish.c
SRCS+= bcrypt.c skipjack.c
SRCS+= crypt.c cryptutil.c arc4random.c arc4random_uniform.c \
blowfish.c bcrypt.c

MAN+= crypt.3 blowfish.3 arc4random.3
MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3
MLINKS+=crypt.3 des_setkey.3 blowfish.3 blf_key.3 blowfish.3 blf_enc.3
MLINKS+=blowfish.3 blf_dec.3 blowfish.3 blf_ecb_encrypt.3
MLINKS+=blowfish.3 blf_ecb_decrypt.3 blowfish.3 blf_cbc_encrypt.3
MLINKS+=blowfish.3 blf_cbc_decrypt.3
MLINKS+=arc4random.3 arc4random_stir.3 arc4random.3 arc4random_addrandom.3
MAN+= crypt.3 crypt_checkpass.3 blowfish.3 arc4random.3
120 changes: 62 additions & 58 deletions src/lib/libc/crypt/arc4random.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $OpenBSD: arc4random.3,v 1.17 2000/12/21 14:07:41 aaron Exp $
.\" $OpenBSD: arc4random.3,v 1.35 2014/11/25 16:45:24 millert Exp $
.\"
.\" Copyright 1997 Niels Provos <[email protected]>
.\" All rights reserved.
Expand Down Expand Up @@ -30,81 +30,85 @@
.\"
.\" Manual page, using -mandoc macros
.\"
.Dd April 15, 1997
.Dd $Mdocdate: November 25 2014 $
.Dt ARC4RANDOM 3
.Os
.Sh NAME
.Nm arc4random ,
.Nm arc4random_stir ,
.Nm arc4random_addrandom
.Nd arc4 random number generator
.Nm arc4random_buf ,
.Nm arc4random_uniform
.Nd random number generator
.Sh SYNOPSIS
.Fd #include <stdlib.h>
.Ft u_int32_t
.In stdlib.h
.Ft uint32_t
.Fn arc4random "void"
.Ft void
.Fn arc4random_stir "void"
.Ft void
.Fn arc4random_addrandom "u_char *dat" "int datlen"
.Fn arc4random_buf "void *buf" "size_t nbytes"
.Ft uint32_t
.Fn arc4random_uniform "uint32_t upper_bound"
.Sh DESCRIPTION
The
.Fn arc4random
function provides a high quality 32-bit pseudo-random
number very quickly.
.Fn arc4random
seeds itself on a regular basis from the kernel strong random number
subsystem described in
.Xr random 4 .
On each call, an ARC4 generator is used to generate a new result.
The
.Fn arc4random
function uses the ARC4 cipher key stream generator,
which uses 8*8 8 bit S-Boxes.
The S-Boxes can be in about (2**1700) states.
.Pp
.Fn arc4random
fits into a middle ground not covered by other subsystems such as
the strong, slow, and resource expensive random
devices described in
.Xr random 4
versus the fast but poor quality interfaces described in
This family of functions provides higher quality data than those
described in
.Xr rand 3 ,
.Xr random 3 ,
and
.Xr drand48 3 .
.Xr rand48 3 .
.Pp
The
.Fn arc4random_stir
function reads data from
.Pa /dev/arandom
and uses it to permute the S-Boxes via
.Fn arc4random_addrandom .
Use of these functions is encouraged for almost all random number
consumption because the other interfaces are deficient in either
quality, portability, standardization, or availability.
These functions can be called in almost all coding environments,
including
.Xr pthreads 3
and
.Xr chroot 2 .
.Pp
There is no need to call
.Fn arc4random_stir
before using
.Fn arc4random ,
since
High quality 32-bit pseudo-random numbers are generated very quickly.
On each call, a cryptographic pseudo-random number generator is used
to generate a new result.
One data pool is used for all consumers in a process, so that consumption
under program flow can act as additional stirring.
The subsystem is re-seeded from the kernel random number subsystem using
.Xr getentropy 2
on a regular basis, and also upon
.Xr fork 2 .
.Pp
The
.Fn arc4random
automatically initializes itself.
function returns a single 32-bit value.
.Pp
.Fn arc4random_buf
fills the region
.Fa buf
of length
.Fa nbytes
with random data.
.Pp
.Fn arc4random_uniform
will return a single 32-bit value, uniformly distributed but less than
.Fa upper_bound .
This is recommended over constructions like
.Dq Li arc4random() % upper_bound
as it avoids "modulo bias" when the upper bound is not a power of two.
In the worst case, this function may consume multiple iterations
to ensure uniformity; see the source code to understand the problem
and solution.
.Sh RETURN VALUES
These functions are always successful, and no return value is
reserved to indicate an error.
.Sh SEE ALSO
.Xr rand 3 ,
.Xr rand48 3 ,
.Xr random 3
.Sh HISTORY
An algorithm called
.Pa RC4
was designed by RSA Data Security, Inc.
It was considered a trade secret, but not trademarked.
Because it was a trade secret, it obviously could not be patented.
A clone of this was posted anonymously to USENET and confirmed to
be equivalent by several sources who had access to the original cipher.
Because of the trade secret situation, RSA Data Security, Inc. can do
nothing about the release of the ARC4 algorithm.
Since
.Pa RC4
used to be a trade secret, the cipher is now referred to as
.Pa ARC4 .
.Pp
These functions first appeared in
.Ox 2.1 .
.Pp
The original version of this random number generator used the
RC4 (also known as ARC4) algorithm.
In
.Ox 5.5
it was replaced with the ChaCha20 cipher, and it may be replaced
again in the future as cryptographic techniques advance.
A good mnemonic is
.Dq A Replacement Call for Random .
Loading