Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-otp/otp-hash.c @ 9266:cd29b745c8dd HEAD
configure: clock_gettime()'s -lrt adding dropped everything else from $LIBS.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 27 Jul 2009 06:32:42 -0400 |
parents | 406c9a863f26 |
children |
rev | line source |
---|---|
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 * OTP hash generaion. |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 * |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 * Copyright (c) 2006 Andrey Panin <pazke@donpac.ru> |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 * |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 * This software is released under the MIT license. |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 */ |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "lib.h" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "md4.h" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "md5.h" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "sha1.h" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "otp.h" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 struct digest { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 const char *name; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 void (*init)(void *ctx); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 void (*update)(void *ctx, const void *data, const size_t size); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 void (*final)(void *ctx, void *res); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 void (*otp_final)(void *ctx, void *res); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 }; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 struct digest_context { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 const struct digest *digest; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 union { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct md4_context md4_ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 struct md5_context md5_ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 struct sha1_ctxt sha1_ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 } ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 }; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 static void md4_fold(struct md4_context *ctx, void *res) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 uint32_t tmp[4], *p = res; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 md4_final(ctx, (unsigned char *) tmp); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 *p++ = tmp[0] ^ tmp[2]; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 *p = tmp[1] ^ tmp[3]; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 static void md5_fold(struct md5_context *ctx, void *res) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 uint32_t tmp[4], *p = res; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 md5_final(ctx, (unsigned char *) tmp); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 *p++ = tmp[0] ^ tmp[2]; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 *p = tmp[1] ^ tmp[3]; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 /* |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 * Sometimes I simply can't look at code generated by gcc. |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 */ |
4962
7d8d82d0e5e5
s/swab/swab_uint32/. swab() already exists in libc and it may conflict.
Timo Sirainen <tss@iki.fi>
parents:
4798
diff
changeset
|
56 static inline uint32_t swab_uint32(uint32_t val) |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 #if defined(__GNUC__) && defined(__i386__) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 asm("xchgb %b0, %h0\n" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 "rorl $16, %0\n" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 "xchgb %b0, %h0\n" |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 :"=q" (val) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 : "0" (val)); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 #else |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 val = ((val & 0xff) << 24) | ((val & 0xff00) << 8) | |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 ((val & 0xff0000) >> 8) | ((val >> 24) & 0xff); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 #endif |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 return val; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 static void sha1_fold(struct sha1_ctxt *ctx, void *res) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 uint32_t tmp[5], *p = res; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 sha1_result(ctx, tmp); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
4962
7d8d82d0e5e5
s/swab/swab_uint32/. swab() already exists in libc and it may conflict.
Timo Sirainen <tss@iki.fi>
parents:
4798
diff
changeset
|
77 *p++ = swab_uint32(tmp[0] ^ tmp[2] ^ tmp[4]); |
7d8d82d0e5e5
s/swab/swab_uint32/. swab() already exists in libc and it may conflict.
Timo Sirainen <tss@iki.fi>
parents:
4798
diff
changeset
|
78 *p = swab_uint32(tmp[1] ^ tmp[3]); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
6496 | 82 #define F(name) ((void (*)()) (name)) |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 static const struct digest digests[] = { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 { "md4", F(md4_init), F(md4_update), F(md4_final), F(md4_fold) }, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 { "md5", F(md5_init), F(md5_update), F(md5_final), F(md5_fold) }, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 { "sha1", F(sha1_init), F(sha1_loop), F(sha1_result), F(sha1_fold) }, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 }; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 #undef F |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 const char *digest_name(unsigned int algo) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 { |
6494
59490181469e
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
Timo Sirainen <tss@iki.fi>
parents:
4962
diff
changeset
|
94 i_assert(algo < N_ELEMENTS(digests)); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 return digests[algo].name; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 int digest_find(const char *name) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 { |
6494
59490181469e
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
Timo Sirainen <tss@iki.fi>
parents:
4962
diff
changeset
|
101 unsigned int i; |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
6494
59490181469e
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
Timo Sirainen <tss@iki.fi>
parents:
4962
diff
changeset
|
103 for (i = 0; i < N_ELEMENTS(digests); i++) |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 if (strcmp(name, digests[i].name) == 0) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 return i; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 return -1; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 int digest_init(struct digest_context *ctx, const unsigned int algo) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 { |
6494
59490181469e
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
Timo Sirainen <tss@iki.fi>
parents:
4962
diff
changeset
|
112 i_assert(algo < N_ELEMENTS(digests)); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 ctx->digest = digests + algo; |
6496 | 115 ctx->digest->init(&ctx->ctx); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 return 0; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 void digest_update(struct digest_context *ctx, const void *data, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 const size_t size) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 { |
6496 | 123 ctx->digest->update(&ctx->ctx, data, size); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 void digest_final(struct digest_context *ctx, unsigned char *result) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 { |
6496 | 128 ctx->digest->final(&ctx->ctx, result); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 void digest_otp_final(struct digest_context *ctx, unsigned char *result) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 { |
6496 | 133 ctx->digest->otp_final(&ctx->ctx, result); |
4798
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 void otp_hash(unsigned int algo, const char *seed, const char *passphrase, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 unsigned int step, unsigned char *result) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 struct digest_context ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 digest_init(&ctx, algo); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 digest_update(&ctx, seed, strlen(seed)); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 digest_update(&ctx, passphrase, strlen(passphrase)); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 digest_otp_final(&ctx, result); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 while (step-- > 0) { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 digest_init(&ctx, algo); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 digest_update(&ctx, result, OTP_HASH_SIZE); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 digest_otp_final(&ctx, result); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 } |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 void otp_next_hash(unsigned int algo, const unsigned char *prev, |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 unsigned char *result) |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 { |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 struct digest_context ctx; |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 digest_init(&ctx, algo); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 digest_update(&ctx, prev, OTP_HASH_SIZE); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 digest_otp_final(&ctx, result); |
c04189d77a59
Added OTP and S/KEY authentication mechanisms. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 } |