| 1 | /* |
| 2 | * This file is part of DisOrder. |
| 3 | * Copyright (C) 2008 Richard Kettlewell, 2018 Mark Wooding |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | #include "test.h" |
| 19 | #include "salsa208.h" |
| 20 | |
| 21 | #define TEST_SALSA208(K, N, P, C) do { \ |
| 22 | Kbytes = unhex(K, &Klen); \ |
| 23 | salsa208_setkey(ac, Kbytes, Klen); \ |
| 24 | Nbytes = unhex(N, &Nlen); \ |
| 25 | salsa208_setnonce(ac, Nbytes, Nlen); \ |
| 26 | Pbytes = unhex(P, &Plen); \ |
| 27 | salsa208_stream(ac, Pbytes, output, Plen); \ |
| 28 | output_hex = hex(output, Plen); \ |
| 29 | check_string(output_hex, C); \ |
| 30 | } while(0) |
| 31 | |
| 32 | static void test_salsa208(void) { |
| 33 | salsa208_context ac[1]; |
| 34 | uint8_t output[80], *Kbytes, *Nbytes, *Pbytes; |
| 35 | char *output_hex; |
| 36 | size_t Klen, Nlen, Plen; |
| 37 | |
| 38 | /* from the eStream submission */ |
| 39 | TEST_SALSA208("0f62b5085bae0154a7fa4da0f34699ec3f92e5388bde3184d72a7dd02376c91c", |
| 40 | "288ff65dc42b92f9", |
| 41 | "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
| 42 | "36ceb42e23ce2fed61d1a4e5a6e0a600dcca12ce4f1316c175c0bde0825d90972f574a7a25665fe6c3b91a70f1b83795330f5cfa8922c8f9b0589beade0b1432"); |
| 43 | |
| 44 | /* test against Catacomb implementation; checks XOR, state stepping */ |
| 45 | TEST_SALSA208("ce9b04eeb18bb1434d6f534880d8516ff65158f60832325269b5c5e517adb27e", |
| 46 | "41f4e1e0db3ef6f2", |
| 47 | "d3df3ab24ce7ef617148fdd461757d81b1b3abecb808b4e3ebb542675597c0ab6a4ae3888a7717a8eb2f80b8a3ca33e8c4280757b2f71d409c8618ee50648e35810dfdcbb3ad9436368fde5e645ef019", |
| 48 | "3132381a28814d1989bcf09656e64a0ee8c6dd723a3ba5f6a02111f86f5156321ea7300976b2393821d44c425754f6cc08b755ea07287cc77fead40c581259d24d127880b7597fc6a9ea8fba89dd3f4c"); |
| 49 | } |
| 50 | |
| 51 | TEST(salsa208); |
| 52 | |
| 53 | /* |
| 54 | Local Variables: |
| 55 | c-basic-offset:2 |
| 56 | comment-column:40 |
| 57 | fill-column:79 |
| 58 | indent-tabs-mode:nil |
| 59 | End: |
| 60 | */ |