543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
-
+
-
+
|
/*
** Compute the SHA3 checksum of a file on disk. Store the resulting
** checksum in the blob pCksum. pCksum is assumed to be initialized.
**
** Return the number of errors.
*/
int sha3sum_file(const char *zFilename, int iSize, Blob *pCksum){
int sha3sum_file(const char *zFilename, int eFType, int iSize, Blob *pCksum){
FILE *in;
SHA3Context ctx;
char zBuf[10240];
if( file_wd_islink(zFilename) ){
if( eFType==RepoFILE && file_islink(zFilename) ){
/* Instead of file content, return sha3 of link destination path */
Blob destinationPath;
int rc;
blob_read_link(&destinationPath, zFilename);
rc = sha3sum_blob(&destinationPath, iSize, pCksum);
blob_reset(&destinationPath);
|
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
|
** If a file is named "-" then take its content from standard input.
**
** To be clear: The official NIST FIPS-202 implementation of SHA3
** with the added 01 padding is used, not the original Keccak submission.
**
** Options:
**
** --224 Compute a SHA3-224 hash
** --256 Compute a SHA3-256 hash (the default)
** --384 Compute a SHA3-384 hash
** --512 Compute a SHA3-512 hash
** --size N An N-bit hash. N must be a multiple of 32 between 128
** and 512.
** --224 Compute a SHA3-224 hash
** --256 Compute a SHA3-256 hash (the default)
** --384 Compute a SHA3-384 hash
** --512 Compute a SHA3-512 hash
** --size N An N-bit hash. N must be a multiple of 32 between
** 128 and 512.
** -h, --dereference If FILE is a symbolic link, compute the hash on
** the object pointed to, not on the link itself.
*/
void sha3sum_test(void){
int i;
Blob in;
Blob cksum;
int iSize = 256;
int eFType = SymFILE;
if( find_option("dereference","h",0) ) eFType = ExtFILE;
if( find_option("224",0,0)!=0 ) iSize = 224;
else if( find_option("256",0,0)!=0 ) iSize = 256;
else if( find_option("384",0,0)!=0 ) iSize = 384;
else if( find_option("512",0,0)!=0 ) iSize = 512;
else{
const char *zN = find_option("size",0,1);
if( zN!=0 ){
|
662
663
664
665
666
667
668
669
670
671
672
673
674
|
666
667
668
669
670
671
672
673
674
675
676
677
678
|
-
+
|
for(i=2; i<g.argc; i++){
blob_init(&cksum, "************** not found ***************", -1);
if( g.argv[i][0]=='-' && g.argv[i][1]==0 ){
blob_read_from_channel(&in, stdin, -1);
sha3sum_blob(&in, iSize, &cksum);
}else{
sha3sum_file(g.argv[i], iSize, &cksum);
sha3sum_file(g.argv[i], eFType, iSize, &cksum);
}
fossil_print("%s %s\n", blob_str(&cksum), g.argv[i]);
blob_reset(&cksum);
}
}
|