|
| 1 | +/* myApp.c |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2022 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfSSL. |
| 6 | + * |
| 7 | + * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfSSL is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +#include <wolfssl/wolfcrypt/settings.h> /* using user_settings.h for example */ |
| 23 | +#include <wolfssl/wolfcrypt/sha256.h> |
| 24 | +#include <wolfssl/wolfcrypt/wc_port.h> |
| 25 | +#include <stdio.h> |
| 26 | + |
| 27 | + |
| 28 | +int main(int argc, char** argv) |
| 29 | +{ |
| 30 | + wc_Sha256 sha; |
| 31 | + byte digest[WC_SHA256_DIGEST_SIZE]; |
| 32 | + int i, ret; |
| 33 | + |
| 34 | + if (argc != 2) { |
| 35 | + printf("%s <to be hashed>\n", argv[0]); |
| 36 | + return -1; |
| 37 | + } |
| 38 | + |
| 39 | + ret = wolfCrypt_Init(); |
| 40 | + if (ret == 0) { |
| 41 | + ret = wc_InitSha256(&sha); |
| 42 | + } |
| 43 | + if (ret == 0) { |
| 44 | + ret = wc_Sha256Update(&sha, (const byte*)argv[1], |
| 45 | + (word32)XSTRLEN(argv[1])); |
| 46 | + } |
| 47 | + if (ret == 0) { |
| 48 | + ret = wc_Sha256Final(&sha, digest); |
| 49 | + } |
| 50 | + |
| 51 | + if (ret != 0) { |
| 52 | + printf("Error %d\n", ret); |
| 53 | + } |
| 54 | + |
| 55 | + if (ret == 0) { |
| 56 | + printf("Hash in hex : "); |
| 57 | + for (i = 0; i < WC_SHA256_DIGEST_SIZE; i++) { |
| 58 | + printf("%02X", digest[i]); |
| 59 | + } |
| 60 | + printf("\n"); |
| 61 | + } |
| 62 | + |
| 63 | + wolfCrypt_Cleanup(); |
| 64 | + return 0; |
| 65 | +} |
0 commit comments