File: sha1test.c

package info (click to toggle)
zsync 0.6.2-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,576 kB
  • sloc: ansic: 9,023; sh: 3,800; makefile: 42
file content (41 lines) | stat: -rw-r--r-- 1,169 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 *   zsync - client side rsync over http
 *   Copyright (C) 2005 Colin Phipps <cph@moria.org.uk>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the Artistic License v2 (see the accompanying 
 *   file COPYING for the full license terms), or, at your option, any later 
 *   version of the same license.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   COPYING file for details.
 */

#include "zsglobal.h"

#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include "sha1.h"

// From RFC3174
const char correct_checksum[SHA1_DIGEST_LENGTH] = {0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D};

int main(void)
{
	SHA1_CTX ctx;

	SHA1Init(&ctx);

	SHA1Update(&ctx,(uint8_t*)"a",1);
	SHA1Update(&ctx,(uint8_t*)"bc",2);
	{
		uint8_t digest[SHA1_DIGEST_LENGTH];
		SHA1Final(digest,&ctx);
		exit(memcmp(digest,correct_checksum,SHA1_DIGEST_LENGTH));
	}

    return 0;
}