File: main.c

package info (click to toggle)
whirlpool 1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 188 kB
  • ctags: 65
  • sloc: ansic: 764; sh: 101; makefile: 90
file content (61 lines) | stat: -rw-r--r-- 1,736 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* This program 2001 by Sam Trenholme.  This is under the same license as
   the rest of the whirlpool code */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>

#include "nessie.h"

main(int argc, char **argv) {
    struct NESSIEstruct whirlpool_ctx;
    int desc, readed, counter;
    char buf[4100];
    char digest[72];

    if(argc != 2) {
        printf("Usage: whirlpool {filename}\n");
	exit(1);
	}
 
    if((desc = open(argv[1],O_RDONLY)) < 0) {
        perror("Could not open file");
	exit(2);
	}

    NESSIEinit(&whirlpool_ctx);
    
    readed = 1;
    while(readed > 0) {
        readed = read(desc,buf,4096);
        if(readed > 0) 
	    NESSIEadd(buf,readed * 8,&whirlpool_ctx);
        }

    NESSIEfinalize(&whirlpool_ctx,digest);

    printf("Whirlpool digest: ");
    for(counter = 0; counter < 64; counter++)
        printf("%02x",digest[counter] & 0xff);
    printf("\n");

    }