BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file OTPCalculator.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | * |
||
29 | * @section DESCRIPTION |
||
30 | * |
||
31 | * Object that calculates OTPs. |
||
32 | */ |
||
33 | |||
34 | #ifndef BADVPN_SECURITY_OTPCALCULATOR_H |
||
35 | #define BADVPN_SECURITY_OTPCALCULATOR_H |
||
36 | |||
37 | #include <stdlib.h> |
||
38 | #include <string.h> |
||
39 | |||
40 | #include <misc/balign.h> |
||
41 | #include <misc/debug.h> |
||
42 | #include <security/BRandom.h> |
||
43 | #include <security/BEncryption.h> |
||
44 | #include <base/DebugObject.h> |
||
45 | |||
46 | /** |
||
47 | * Type for an OTP. |
||
48 | */ |
||
49 | typedef uint32_t otp_t; |
||
50 | |||
51 | /** |
||
52 | * Object that calculates OTPs. |
||
53 | */ |
||
54 | typedef struct { |
||
55 | DebugObject d_obj; |
||
56 | int num_otps; |
||
57 | int cipher; |
||
58 | int block_size; |
||
59 | size_t num_blocks; |
||
60 | otp_t *data; |
||
61 | } OTPCalculator; |
||
62 | |||
63 | /** |
||
64 | * Initializes the calculator. |
||
65 | * {@link BSecurity_GlobalInitThreadSafe} must have been done if this object |
||
66 | * will be used from a non-main thread. |
||
67 | * |
||
68 | * @param calc the object |
||
69 | * @param num_otps number of OTPs to generate from a seed. Must be >=0. |
||
70 | * @param cipher encryption cipher for calculating the OTPs. Must be valid |
||
71 | * according to {@link BEncryption_cipher_valid}. |
||
72 | * @return 1 on success, 0 on failure |
||
73 | */ |
||
74 | int OTPCalculator_Init (OTPCalculator *calc, int num_otps, int cipher) WARN_UNUSED; |
||
75 | |||
76 | /** |
||
77 | * Frees the calculator. |
||
78 | * |
||
79 | * @param calc the object |
||
80 | */ |
||
81 | void OTPCalculator_Free (OTPCalculator *calc); |
||
82 | |||
83 | /** |
||
84 | * Generates OTPs from the given key and IV. |
||
85 | * |
||
86 | * @param calc the object |
||
87 | * @param key encryption key |
||
88 | * @param iv initialization vector |
||
89 | * @param shuffle whether to shuffle the OTPs. Must be 1 or 0. |
||
90 | * @return pointer to an array of 32-bit OPTs. Constains as many OTPs as was specified |
||
91 | * in {@link OTPCalculator_Init}. Valid until the next generation or |
||
92 | * until the object is freed. |
||
93 | */ |
||
94 | otp_t * OTPCalculator_Generate (OTPCalculator *calc, uint8_t *key, uint8_t *iv, int shuffle); |
||
95 | |||
96 | #endif |