]>
git.saurik.com Git - apple/security.git/blob - sec/SecurityTool/digest_calc.c
3 // Digest calculation command for SecurityTool
5 // Created by John Kelley on 4/27/11.
6 // Copyright 2011 Apple, Inc. All rights reserved.
9 #include "builtin_commands.h"
14 #include <SecurityTool/readline.h>
16 #include <corecrypto/ccsha1.h>
17 #include <corecrypto/ccsha2.h>
19 extern int command_digest(int argc
, char * const *argv
)
24 const struct ccdigest_info
*di
;
25 unsigned char *digest
= NULL
;
29 return 2; /* Return 2 triggers usage message. */
31 if (strcasecmp("sha1", argv
[1]) == 0)
33 //printf("Calculating sha1\n");
36 else if (strcasecmp("sha256", argv
[1]) == 0)
38 //printf("Calculating sha256\n");
41 else if (strcasecmp("sha512", argv
[1]) == 0)
43 //printf("Calculating sha256\n");
47 return 2; /* Return 2 triggers usage message. */
49 digest
= malloc(di
->output_size
);
53 for (i
= 2; i
< (unsigned int)argc
; ++i
)
55 printf("%s(%s)= ", argv
[1], argv
[i
]);
56 if (read_file( argv
[i
], &data
, &data_len
) != 0 || !data
)
58 printf("error reading file\n");
61 ccdigest(di
, data_len
, data
, digest
);
63 for (j
= 0; j
< di
->output_size
; j
++)
64 printf("%02x", digest
[j
]);