3 * Cryptographic challenges
5 * (c) 2005 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Trivial IP Encryption (TrIPE).
12 * TrIPE is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 3 of the License, or (at your
15 * option) any later version.
17 * TrIPE is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License
23 * along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
26 /*----- Header files ------------------------------------------------------*/
30 /*----- Static variables --------------------------------------------------*/
32 static bulkchal *bulk;
36 /*----- Main code ---------------------------------------------------------*/
38 /* --- @c_genkey@ --- *
44 * Use: Generates a new challenge key.
47 static void c_genkey(void)
49 if (bulk && bulk->ops == master->algs.bulk->ops && oseq < 0x07ffffff)
51 if (bulk) bulk->ops->freechal(bulk);
52 bulk = master->algs.bulk->ops->genchal(master->algs.bulk);
53 bulk->ops = master->algs.bulk->ops;
60 * Arguments: @buf *b@ = where to put the challenge
62 * Returns: Zero if OK, nonzero on error.
64 * Use: Issues a new challenge.
73 if (buf_putu32(b, oseq++) || !buf_get(b, bulk->tagsz)) return (-1);
74 if (bulk->ops->chaltag(bulk, p, 4, p + 4)) return (-1);
76 trace(T_CHAL, "chal: issuing challenge %lu", (unsigned long)(oseq - 1));
77 trace_block(T_CRYPTO, "chal: challenge block", p, BCUR(b) - p);
82 /* --- @c_check@ --- *
84 * Arguments: @buf *b@ = where to find the challenge
86 * Returns: Zero if OK, nonzero if it didn't work.
88 * Use: Checks a challenge. On failure, the buffer is broken.
98 a_warn("CHAL", "impossible-challenge", A_END);
101 sz = 4 + bulk->tagsz;
102 if ((p = buf_get(b, sz)) == 0) {
103 a_warn("CHAL", "invalid-challenge", A_END);
106 IF_TRACING(T_CHAL, trace_block(T_CRYPTO, "chal: check challenge", p, sz); )
107 if (bulk->ops->chalvrf(bulk, p, 4, p + 4)) {
108 a_warn("CHAL", "incorrect-tag", A_END);
112 if (seq_check(&iseq, seq, "CHAL"))
114 T( trace(T_CHAL, "chal: checked challenge %lu", (unsigned long)seq); )
122 /*----- That's all, folks -------------------------------------------------*/