| 1 | /* |
| 2 | Copyright (c) 2017, MariaDB |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 16 | |
| 17 | #include <tap.h> |
| 18 | #include <m_string.h> |
| 19 | #include "common.h" |
| 20 | |
| 21 | int main() |
| 22 | { |
| 23 | uchar pk[CRYPTO_PUBLICKEYBYTES]; |
| 24 | uchar foobar_pk[CRYPTO_PUBLICKEYBYTES]= {170, 253, 166, 27, 161, 214, 10, |
| 25 | 236, 183, 217, 41, 91, 231, 24, 85, 225, 49, 210, 181, 236, 13, 207, 101, |
| 26 | 72, 53, 83, 219, 130, 79, 151, 0, 159}; |
| 27 | uchar foobar_sign[CRYPTO_BYTES]= {232, 61, 201, 63, 67, 63, 51, 53, 86, 73, |
| 28 | 238, 35, 170, 117, 146, 214, 26, 17, 35, 9, 8, 132, 245, 141, 48, 99, 66, |
| 29 | 58, 36, 228, 48, 84, 115, 254, 187, 168, 88, 162, 249, 57, 35, 85, 79, 238, |
| 30 | 167, 106, 68, 117, 56, 135, 171, 47, 20, 14, 133, 79, 15, 229, 124, 160, |
| 31 | 176, 100, 138, 14}; |
| 32 | |
| 33 | uchar nonce[NONCE_BYTES]; |
| 34 | uchar reply[NONCE_BYTES+CRYPTO_BYTES]; |
| 35 | int r; |
| 36 | |
| 37 | plan(4); |
| 38 | |
| 39 | crypto_sign_keypair(pk, USTRING_WITH_LEN("foobar" )); |
| 40 | ok(!memcmp(pk, foobar_pk, CRYPTO_PUBLICKEYBYTES), "foobar pk" ); |
| 41 | |
| 42 | memset(nonce, 'A', sizeof(nonce)); |
| 43 | crypto_sign(reply, nonce, sizeof(nonce), USTRING_WITH_LEN("foobar" )); |
| 44 | ok(!memcmp(reply, foobar_sign, CRYPTO_BYTES), "foobar sign" ); |
| 45 | |
| 46 | r= crypto_sign_open(reply, sizeof(reply), pk); |
| 47 | ok(!r, "good nonce" ); |
| 48 | |
| 49 | crypto_sign(reply, nonce, sizeof(nonce), USTRING_WITH_LEN("foobar" )); |
| 50 | reply[CRYPTO_BYTES + 10]='B'; |
| 51 | r= crypto_sign_open(reply, sizeof(reply), pk); |
| 52 | ok(r, "bad nonce" ); |
| 53 | |
| 54 | return exit_status(); |
| 55 | } |
| 56 | |