diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/crypt/Makefile.inc | 7 | ||||
| -rw-r--r-- | src/lib/libc/crypt/bcrypt.c | 8 | ||||
| -rw-r--r-- | src/lib/libc/crypt/blowfish.3 | 84 | ||||
| -rw-r--r-- | src/lib/libc/crypt/blowfish.c | 20 |
4 files changed, 99 insertions, 20 deletions
diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc index 82091eaaae..af67278f44 100644 --- a/src/lib/libc/crypt/Makefile.inc +++ b/src/lib/libc/crypt/Makefile.inc | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.6 1997/02/13 16:59:53 provos Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.7 1997/02/16 20:58:11 provos Exp $ |
| 2 | 2 | ||
| 3 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/crypt ${.CURDIR}/crypt | 3 | .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/crypt ${.CURDIR}/crypt |
| 4 | 4 | ||
| 5 | SRCS+= crypt.c morecrypt.c md5crypt.c arc4random.c blowfish.c | 5 | SRCS+= crypt.c morecrypt.c md5crypt.c arc4random.c blowfish.c |
| 6 | SRCS+= bcrypt.c | 6 | SRCS+= bcrypt.c |
| 7 | 7 | ||
| 8 | MAN+= crypt.3 | 8 | MAN+= crypt.3 blowfish.3 |
| 9 | MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 | 9 | MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 |
| 10 | MLINKS+=crypt.3 des_setkey.3 | 10 | MLINKS+=crypt.3 des_setkey.3 blowfish.3 blf_key.3 blowfish.3 blf_enc.3 |
| 11 | MLINKS+=blowfish.3 blf_dec.3 | ||
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c index d2b7cd888c..364555b5da 100644 --- a/src/lib/libc/crypt/bcrypt.c +++ b/src/lib/libc/crypt/bcrypt.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bcrypt.c,v 1.2 1997/02/14 18:40:14 provos Exp $ */ | 1 | /* $OpenBSD: bcrypt.c,v 1.3 1997/02/16 20:58:15 provos Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 3 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
| 4 | * All rights reserved. | 4 | * All rights reserved. |
| @@ -13,7 +13,7 @@ | |||
| 13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. All advertising materials mentioning features or use of this software |
| 15 | * must display the following acknowledgement: | 15 | * must display the following acknowledgement: |
| 16 | * This product includes software developed by Theo de Raadt. | 16 | * This product includes software developed by Niels Provos. |
| 17 | * 4. The name of the author may not be used to endorse or promote products | 17 | * 4. The name of the author may not be used to endorse or promote products |
| 18 | * derived from this software without specific prior written permission. | 18 | * derived from this software without specific prior written permission. |
| 19 | * | 19 | * |
| @@ -37,7 +37,7 @@ | |||
| 37 | * REPEAT rounds: | 37 | * REPEAT rounds: |
| 38 | * state := ExpandKey (state, 0, salt) | 38 | * state := ExpandKey (state, 0, salt) |
| 39 | * state := ExpandKey(state, 0, password) | 39 | * state := ExpandKey(state, 0, password) |
| 40 | * 4. ctext := "OpenBSDbcrypthashfunc" | 40 | * 4. ctext := "OrpheanBeholderScryDoubt" |
| 41 | * 5. REPEAT 64: | 41 | * 5. REPEAT 64: |
| 42 | * ctext := Encrypt_ECB (state, ctext); | 42 | * ctext := Encrypt_ECB (state, ctext); |
| 43 | * 6. RETURN Concatenate (salt, ctext); | 43 | * 6. RETURN Concatenate (salt, ctext); |
| @@ -187,7 +187,7 @@ bcrypt(key, salt) | |||
| 187 | u_int32_t rounds, i, k; | 187 | u_int32_t rounds, i, k; |
| 188 | u_int16_t j; | 188 | u_int16_t j; |
| 189 | u_int8_t key_len, salt_len, logr; | 189 | u_int8_t key_len, salt_len, logr; |
| 190 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OpenBSDbcrypthashfunc"; | 190 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; |
| 191 | u_int8_t csalt[BCRYPT_MAXSALT]; | 191 | u_int8_t csalt[BCRYPT_MAXSALT]; |
| 192 | u_int32_t cdata[BCRYPT_BLOCKS]; | 192 | u_int32_t cdata[BCRYPT_BLOCKS]; |
| 193 | /* Discard "$" identifier */ | 193 | /* Discard "$" identifier */ |
diff --git a/src/lib/libc/crypt/blowfish.3 b/src/lib/libc/crypt/blowfish.3 new file mode 100644 index 0000000000..0b45790658 --- /dev/null +++ b/src/lib/libc/crypt/blowfish.3 | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | .\" $OpenBSD: blowfish.3,v 1.1 1997/02/16 20:58:16 provos Exp $ | ||
| 2 | .\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | ||
| 3 | .\" All rights reserved. | ||
| 4 | .\" | ||
| 5 | .\" Redistribution and use in source and binary forms, with or without | ||
| 6 | .\" modification, are permitted provided that the following conditions | ||
| 7 | .\" are met: | ||
| 8 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 9 | .\" notice, this list of conditions and the following disclaimer. | ||
| 10 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 11 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 12 | .\" documentation and/or other materials provided with the distribution. | ||
| 13 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 14 | .\" must display the following acknowledgement: | ||
| 15 | .\" This product includes software developed by Niels Provos. | ||
| 16 | .\" 4. The name of the author may not be used to endorse or promote products | ||
| 17 | .\" derived from this software without specific prior written permission. | ||
| 18 | .\" | ||
| 19 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 20 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 21 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 22 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 24 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 28 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | .\" | ||
| 30 | .\" Manual page, using -mandoc macros | ||
| 31 | .\" | ||
| 32 | .Dd February 13, 1997 | ||
| 33 | .Dt BLOWFISH 3 | ||
| 34 | .Os "OpenBSD 2.0" | ||
| 35 | .Sh NAME | ||
| 36 | .Nm blf_key, | ||
| 37 | .Nm blf_enc, | ||
| 38 | .Nm blf_dec | ||
| 39 | .Nd Blowfish encryption | ||
| 40 | .Sh SYNOPSIS | ||
| 41 | .Fd #include <blf.h> | ||
| 42 | .Ft void | ||
| 43 | .Fn blf_key "blf_ctx *state" "const u_int8_t *key" "u_int16_t keylen" | ||
| 44 | .Ft void | ||
| 45 | .Fn blf_enc "blf_ctx *state" "u_int32_t *data" "u_int16_t datalen" | ||
| 46 | .Ft void | ||
| 47 | .Fn blf_dec "blf_ctx *state" "u_int32_t *data" "u_int16_t datalen" | ||
| 48 | .Sh DESCRIPTION | ||
| 49 | .Pa Blowfish | ||
| 50 | is a fast unpatented block cipher designed by Bruce Schneier. | ||
| 51 | It basically consists of a 16 times iterated Feistel network. | ||
| 52 | The block size is 64 bit and the key size is maximal 448 bit. | ||
| 53 | .Pp | ||
| 54 | The | ||
| 55 | .Fn blf_key | ||
| 56 | function initializes the 4 8bit S-boxes and the 18 Subkeys with | ||
| 57 | the hexadecimal digits of Pi. The key is used for further randomization. | ||
| 58 | The first argument to | ||
| 59 | .Fn blf_enc | ||
| 60 | is the initalized state derived from | ||
| 61 | .Fn blf_key . | ||
| 62 | The stream of data is encrypted in Electronic Cookbook Mode (ECB) and | ||
| 63 | .Pa datalen | ||
| 64 | must be even. | ||
| 65 | .Fn blf_dec | ||
| 66 | is used for decrypting Blowfish encrypted blocks. | ||
| 67 | .Pp | ||
| 68 | The functions | ||
| 69 | .Fn Blowfish_initstate , | ||
| 70 | .Fn Blowfish_expand0state , | ||
| 71 | .Fn Blowfish_expandstate , | ||
| 72 | .Fn Blowfish_encipher | ||
| 73 | and | ||
| 74 | .Fn Blowfish_decipher | ||
| 75 | are used for customization of the | ||
| 76 | .Pa Blowfish | ||
| 77 | cipher, i.e. for the blowfish password hashing function or for | ||
| 78 | implementation of Cipher Block Chaining Mode (CBC). | ||
| 79 | .Sh SEE ALSO | ||
| 80 | .Xr crypt 3 , | ||
| 81 | .Xr passwd 1 , | ||
| 82 | .Xr passwd 5 | ||
| 83 | .Sh AUTHOR | ||
| 84 | Niels Provos <provos@physnet.uni-hamburg.de> | ||
diff --git a/src/lib/libc/crypt/blowfish.c b/src/lib/libc/crypt/blowfish.c index 558d6d7b38..21c492209d 100644 --- a/src/lib/libc/crypt/blowfish.c +++ b/src/lib/libc/crypt/blowfish.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: blowfish.c,v 1.2 1997/02/14 18:40:18 provos Exp $ */ | 1 | /* $OpenBSD: blowfish.c,v 1.3 1997/02/16 20:58:17 provos Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Blowfish block cipher for OpenBSD | 3 | * Blowfish block cipher for OpenBSD |
| 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
| @@ -16,7 +16,7 @@ | |||
| 16 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
| 18 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
| 19 | * This product includes software developed by Theo de Raadt. | 19 | * This product includes software developed by Niels Provos. |
| 20 | * 4. The name of the author may not be used to endorse or promote products | 20 | * 4. The name of the author may not be used to endorse or promote products |
| 21 | * derived from this software without specific prior written permission. | 21 | * derived from this software without specific prior written permission. |
| 22 | * | 22 | * |
| @@ -56,12 +56,6 @@ | |||
| 56 | 56 | ||
| 57 | static inline u_int32_t F __P((blf_ctx * bc, u_int32_t x)); | 57 | static inline u_int32_t F __P((blf_ctx * bc, u_int32_t x)); |
| 58 | 58 | ||
| 59 | /* Standard Blowfish */ | ||
| 60 | |||
| 61 | void blf_key __P((blf_ctx * c, u_int8_t * k, u_int16_t len)); | ||
| 62 | void blf_enc __P((blf_ctx * c, u_int32_t * data, u_int16_t blocks)); | ||
| 63 | void blf_dec __P((blf_ctx * c, u_int32_t * data, u_int16_t blocks)); | ||
| 64 | |||
| 65 | /* Function for Feistel Networks */ | 59 | /* Function for Feistel Networks */ |
| 66 | 60 | ||
| 67 | static inline u_int32_t | 61 | static inline u_int32_t |
| @@ -449,7 +443,7 @@ Blowfish_initstate(c) | |||
| 449 | 443 | ||
| 450 | u_int32_t | 444 | u_int32_t |
| 451 | Blowfish_stream2word(data, databytes, current) | 445 | Blowfish_stream2word(data, databytes, current) |
| 452 | u_int8_t *data; | 446 | const u_int8_t *data; |
| 453 | u_int16_t databytes; | 447 | u_int16_t databytes; |
| 454 | u_int16_t *current; | 448 | u_int16_t *current; |
| 455 | { | 449 | { |
| @@ -473,7 +467,7 @@ Blowfish_stream2word(data, databytes, current) | |||
| 473 | void | 467 | void |
| 474 | Blowfish_expand0state(c, key, keybytes) | 468 | Blowfish_expand0state(c, key, keybytes) |
| 475 | blf_ctx *c; | 469 | blf_ctx *c; |
| 476 | u_int8_t *key; | 470 | const u_int8_t *key; |
| 477 | u_int16_t keybytes; | 471 | u_int16_t keybytes; |
| 478 | { | 472 | { |
| 479 | u_int16_t i; | 473 | u_int16_t i; |
| @@ -515,9 +509,9 @@ Blowfish_expand0state(c, key, keybytes) | |||
| 515 | void | 509 | void |
| 516 | Blowfish_expandstate(c, data, databytes, key, keybytes) | 510 | Blowfish_expandstate(c, data, databytes, key, keybytes) |
| 517 | blf_ctx *c; | 511 | blf_ctx *c; |
| 518 | u_int8_t *data; | 512 | const u_int8_t *data; |
| 519 | u_int16_t databytes; | 513 | u_int16_t databytes; |
| 520 | u_int8_t *key; | 514 | const u_int8_t *key; |
| 521 | u_int16_t keybytes; | 515 | u_int16_t keybytes; |
| 522 | { | 516 | { |
| 523 | u_int16_t i; | 517 | u_int16_t i; |
| @@ -562,7 +556,7 @@ Blowfish_expandstate(c, data, databytes, key, keybytes) | |||
| 562 | void | 556 | void |
| 563 | blf_key(c, k, len) | 557 | blf_key(c, k, len) |
| 564 | blf_ctx *c; | 558 | blf_ctx *c; |
| 565 | u_int8_t *k; | 559 | const u_int8_t *k; |
| 566 | u_int16_t len; | 560 | u_int16_t len; |
| 567 | { | 561 | { |
| 568 | /* Initalize S-boxes and subkeys with Pi */ | 562 | /* Initalize S-boxes and subkeys with Pi */ |
