(root)/
util-linux-2.39/
tests/
helpers/
test_sha1.c
       1  /*
       2   * SPDX-License-Identifier: GPL-2.0-or-later
       3   *
       4   * Copyright (C) 2017 Philip Prindeville <philipp@redfish-solutions.com>
       5   */
       6  #include <stdio.h>
       7  #include <unistd.h>
       8  #include <err.h>
       9  #include <stdlib.h>
      10  
      11  #include "sha1.h"
      12  
      13  int main(void)
      14  {
      15  	int i, ret;
      16  	UL_SHA1_CTX ctx;
      17  	unsigned char digest[UL_SHA1LENGTH];
      18  	unsigned char buf[BUFSIZ];
      19  
      20  	ul_SHA1Init( &ctx );
      21  
      22  	while(!feof(stdin) && !ferror(stdin)) {
      23  		ret = fread(buf, 1, sizeof(buf), stdin);
      24  		if (ret)
      25  			ul_SHA1Update( &ctx, buf, ret );
      26  	}
      27  
      28  	if(freopen ("/dev/null", "r", stdin) == NULL)
      29  		err(EXIT_FAILURE, "stdin->null failed!");
      30  
      31  	ul_SHA1Final( digest, &ctx );
      32  
      33  	for (i = 0; i < UL_SHA1LENGTH; i++)
      34  		printf( "%02x", digest[i] );
      35  	printf("\n");
      36  	return 0;
      37  }