"Fossies" - the Fresh Open Source Software Archive

Member "zsync-0.6.2/libzsync/sha1test.c" (16 Sep 2010, 1169 Bytes) of package /linux/privat/old/zsync-0.6.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sha1test.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *   zsync - client side rsync over http
    3  *   Copyright (C) 2005 Colin Phipps <cph@moria.org.uk>
    4  *
    5  *   This program is free software; you can redistribute it and/or modify
    6  *   it under the terms of the Artistic License v2 (see the accompanying 
    7  *   file COPYING for the full license terms), or, at your option, any later 
    8  *   version of the same license.
    9  *
   10  *   This program is distributed in the hope that it will be useful,
   11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *   COPYING file for details.
   14  */
   15 
   16 #include "zsglobal.h"
   17 
   18 #include <string.h>
   19 #include <stdlib.h>
   20 #include <sys/types.h>
   21 #include "sha1.h"
   22 
   23 // From RFC3174
   24 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};
   25 
   26 int main(void)
   27 {
   28     SHA1_CTX ctx;
   29 
   30     SHA1Init(&ctx);
   31 
   32     SHA1Update(&ctx,(uint8_t*)"a",1);
   33     SHA1Update(&ctx,(uint8_t*)"bc",2);
   34     {
   35         uint8_t digest[SHA1_DIGEST_LENGTH];
   36         SHA1Final(digest,&ctx);
   37         exit(memcmp(digest,correct_checksum,SHA1_DIGEST_LENGTH));
   38     }
   39 
   40     return 0;
   41 }