| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bcrypt.c,v 1.10 2011/05/16 10:45:56 drochner Exp $ */ | | 1 | /* $NetBSD: bcrypt.c,v 1.11 2011/12/26 21:51:53 christos Exp $ */ |
2 | /* $OpenBSD: bcrypt.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */ | | 2 | /* $OpenBSD: bcrypt.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | | 5 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -36,27 +36,27 @@ | | | @@ -36,27 +36,27 @@ |
36 | * | | 36 | * |
37 | * 1. state := InitState () | | 37 | * 1. state := InitState () |
38 | * 2. state := ExpandKey (state, salt, password) 3. | | 38 | * 2. state := ExpandKey (state, salt, password) 3. |
39 | * REPEAT rounds: | | 39 | * REPEAT rounds: |
40 | * state := ExpandKey (state, 0, salt) | | 40 | * state := ExpandKey (state, 0, salt) |
41 | * state := ExpandKey(state, 0, password) | | 41 | * state := ExpandKey(state, 0, password) |
42 | * 4. ctext := "OrpheanBeholderScryDoubt" | | 42 | * 4. ctext := "OrpheanBeholderScryDoubt" |
43 | * 5. REPEAT 64: | | 43 | * 5. REPEAT 64: |
44 | * ctext := Encrypt_ECB (state, ctext); | | 44 | * ctext := Encrypt_ECB (state, ctext); |
45 | * 6. RETURN Concatenate (salt, ctext); | | 45 | * 6. RETURN Concatenate (salt, ctext); |
46 | * | | 46 | * |
47 | */ | | 47 | */ |
48 | #include <sys/cdefs.h> | | 48 | #include <sys/cdefs.h> |
49 | __RCSID("$NetBSD: bcrypt.c,v 1.10 2011/05/16 10:45:56 drochner Exp $"); | | 49 | __RCSID("$NetBSD: bcrypt.c,v 1.11 2011/12/26 21:51:53 christos Exp $"); |
50 | | | 50 | |
51 | #include <stdio.h> | | 51 | #include <stdio.h> |
52 | #include <stdlib.h> | | 52 | #include <stdlib.h> |
53 | #include <sys/types.h> | | 53 | #include <sys/types.h> |
54 | #include <string.h> | | 54 | #include <string.h> |
55 | #include <pwd.h> | | 55 | #include <pwd.h> |
56 | #include <errno.h> | | 56 | #include <errno.h> |
57 | #include <limits.h> | | 57 | #include <limits.h> |
58 | | | 58 | |
59 | #include "crypt.h" | | 59 | #include "crypt.h" |
60 | #include "blowfish.c" | | 60 | #include "blowfish.c" |
61 | | | 61 | |
62 | /* This implementation is adaptable to current computing power. | | 62 | /* This implementation is adaptable to current computing power. |
| @@ -67,27 +67,27 @@ __RCSID("$NetBSD: bcrypt.c,v 1.10 2011/0 | | | @@ -67,27 +67,27 @@ __RCSID("$NetBSD: bcrypt.c,v 1.10 2011/0 |
67 | #define BCRYPT_VERSION '2' | | 67 | #define BCRYPT_VERSION '2' |
68 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ | | 68 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ |
69 | #define BCRYPT_MAXSALTLEN (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1) | | 69 | #define BCRYPT_MAXSALTLEN (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1) |
70 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ | | 70 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ |
71 | #define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ | | 71 | #define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ |
72 | | | 72 | |
73 | static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); | | 73 | static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); |
74 | static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); | | 74 | static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); |
75 | static void decode_base64(u_int8_t *, u_int16_t, const u_int8_t *); | | 75 | static void decode_base64(u_int8_t *, u_int16_t, const u_int8_t *); |
76 | | | 76 | |
77 | char *__bcrypt(const char *, const char *); /* XXX */ | | 77 | char *__bcrypt(const char *, const char *); /* XXX */ |
78 | | | 78 | |
79 | static char encrypted[_PASSWORD_LEN]; | | 79 | static char encrypted[_PASSWORD_LEN]; |
80 | static char error[] = ":"; | | 80 | static char error[] = ":1"; |
81 | | | 81 | |
82 | static const u_int8_t Base64Code[] = | | 82 | static const u_int8_t Base64Code[] = |
83 | "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | | 83 | "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
84 | | | 84 | |
85 | char *bcrypt_gensalt(u_int8_t); | | 85 | char *bcrypt_gensalt(u_int8_t); |
86 | | | 86 | |
87 | static const u_int8_t index_64[128] = | | 87 | static const u_int8_t index_64[128] = |
88 | { | | 88 | { |
89 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | | 89 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
90 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | | 90 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
91 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | | 91 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
92 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, | | 92 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
93 | 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, | | 93 | 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, |