Ben Cheng | cc6695e | 2012-03-07 23:04:02 -0800 | [diff] [blame^] | 1 | /* Copyright (C) 2008 Red Hat, Inc. |
| 2 | This file is part of Red Hat elfutils. |
| 3 | Written by Ulrich Drepper <drepper@redhat.com>, 2008. |
| 4 | |
| 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
| 8 | |
| 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
| 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
| 17 | |
| 18 | Red Hat elfutils is an included package of the Open Invention Network. |
| 19 | An included package of the Open Invention Network is a package for which |
| 20 | Open Invention Network licensees cross-license their patents. No patent |
| 21 | license is granted, either expressly or impliedly, by designation as an |
| 22 | included package. Should you wish to participate in the Open Invention |
| 23 | Network licensing program, please visit www.openinventionnetwork.com |
| 24 | <http://www.openinventionnetwork.com>. */ |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | #include <sha1.h> |
| 30 | |
| 31 | |
| 32 | int |
| 33 | main (void) |
| 34 | { |
| 35 | char buf[1000]; |
| 36 | int result = 0; |
| 37 | |
| 38 | struct sha1_ctx ctx; |
| 39 | sha1_init_ctx (&ctx); |
| 40 | sha1_process_bytes ("abc", 3, &ctx); |
| 41 | sha1_finish_ctx (&ctx, buf); |
| 42 | static const char expected1[SHA1_DIGEST_SIZE] = |
| 43 | "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e" |
| 44 | "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d"; |
| 45 | if (memcmp (buf, expected1, SHA1_DIGEST_SIZE) != 0) |
| 46 | { |
| 47 | puts ("test 1 failed"); |
| 48 | result = 1; |
| 49 | } |
| 50 | |
| 51 | sha1_init_ctx (&ctx); |
| 52 | sha1_process_bytes ("\ |
| 53 | abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56, &ctx); |
| 54 | sha1_finish_ctx (&ctx, buf); |
| 55 | static const char expected2[SHA1_DIGEST_SIZE] = |
| 56 | "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae" |
| 57 | "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1"; |
| 58 | if (memcmp (buf, expected2, SHA1_DIGEST_SIZE) != 0) |
| 59 | { |
| 60 | puts ("test 2 failed"); |
| 61 | result = 1; |
| 62 | } |
| 63 | |
| 64 | sha1_init_ctx (&ctx); |
| 65 | memset (buf, 'a', sizeof (buf)); |
| 66 | for (int i = 0; i < 1000; ++i) |
| 67 | sha1_process_bytes (buf, sizeof (buf), &ctx); |
| 68 | sha1_finish_ctx (&ctx, buf); |
| 69 | static const char expected3[SHA1_DIGEST_SIZE] = |
| 70 | "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e" |
| 71 | "\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f"; |
| 72 | if (memcmp (buf, expected3, SHA1_DIGEST_SIZE) != 0) |
| 73 | { |
| 74 | puts ("test 3 failed"); |
| 75 | result = 1; |
| 76 | } |
| 77 | |
| 78 | return result; |
| 79 | } |