Back to index

glibc  2.9
Functions | Variables
sha512test.c File Reference
#include <string.h>
#include "sha512.h"

Go to the source code of this file.

Functions

int main (void)

Variables

struct {
const char * input
const char result [64]
tests []

Function Documentation

int main ( void  )

Definition at line 64 of file sha512test.c.

{
  struct sha512_ctx ctx;
  char sum[64];
  int result = 0;
  int cnt;

  for (cnt = 0; cnt < (int) (sizeof (tests) / sizeof (tests[0])); ++cnt)
    {
      __sha512_init_ctx (&ctx);
      __sha512_process_bytes (tests[cnt].input, strlen (tests[cnt].input),
                           &ctx);
      __sha512_finish_ctx (&ctx, sum);
      if (memcmp (tests[cnt].result, sum, 64) != 0)
       {
         printf ("test %d run %d failed\n", cnt, 1);
         result = 1;
       }

      __sha512_init_ctx (&ctx);
      for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
       __sha512_process_bytes (&tests[cnt].input[i], 1, &ctx);
      __sha512_finish_ctx (&ctx, sum);
      if (memcmp (tests[cnt].result, sum, 64) != 0)
       {
         printf ("test %d run %d failed\n", cnt, 2);
         result = 1;
       }
    }

  /* Test vector from FIPS 180-2: appendix C.3.  */
  char buf[1000];
  memset (buf, 'a', sizeof (buf));
  __sha512_init_ctx (&ctx);
  for (int i = 0; i < 1000; ++i)
    __sha512_process_bytes (buf, sizeof (buf), &ctx);
  __sha512_finish_ctx (&ctx, sum);
  static const char expected[64] =
    "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
    "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
    "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
    "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
  if (memcmp (expected, sum, 64) != 0)
    {
      printf ("test %d failed\n", cnt);
      result = 1;
    }

  return result;
}

Here is the call graph for this function:


Variable Documentation

struct { ... } tests[] [static]