/* Copyright 2002 Colin Percival For the terms under which this work may be distributed, please see the adjoining file "LICENSE". */ /* verify.c Reads a 256 byte signature from stdin, reads a public key from pub.key, and outputs the verified data to stdout. (If the signature is invalid, zero bytes will be written.) Typical usage: md5 -q ${FILE} > ${FILE}.md5 && \ cat ${FILE}.sig | ./verify | cmp -s - ${FILE}.md5 && \ echo "Verified!" Signatures are generated by sign.c */ #include #include #include "ptypes.h" #include "rsa.h" #define KEYLEN 2048 int main(int argc,char *argv[]) { uint8 *dat,*pub,*T1; uint32 len; FILE * f; dat=malloc(KEYLEN/8); pub=malloc(KEYLEN/8); T1=malloc(KEYLEN*8); if((!dat)||(!pub)||(!T1)) { fprintf(stderr,"Out of memory\n"); return 1; }; if((f=fopen("pub.key","r"))==NULL) { fprintf(stderr,"Could not open public key file\n"); return 1; }; if(fread(pub,KEYLEN/8,1,f)<1) { fprintf(stderr,"Error reading from public key file\n"); return 1; }; if(fclose(f)) { fprintf(stderr,"Error closing public key file\n"); return 1; }; if(fread(dat,KEYLEN/8,1,stdin)<1) { fprintf(stderr,"Error reading %d bytes from stdin\n",KEYLEN/8); return 1; }; len=rsa_verify(dat,dat,pub,KEYLEN,T1); if(fwrite(dat,len,1,stdout)<1) { fprintf(stderr,"Error writing to stdout\n"); return 1; }; free(T1); free(pub); free(dat); return 0; }