/*! \brief Compute SHA384 checksum */ void compute_sha384(char *dst, u_int8_t *src, int src_len) { SHA384_CTX ctx384; SHA384_Init(&ctx384); SHA384_Update(&ctx384, src, src_len); SHA384_End(&ctx384, dst); }
static mrb_value sha384_hexdigest(mrb_state *mrb, mrb_value self) { char *hexdigest = (char*)mrb_malloc(mrb, SHA384_DIGEST_STRING_LENGTH); SHA384_CTX ctx = *(SHA384_CTX*)DATA_PTR(self); SHA384_End(&ctx, hexdigest); return mrb_str_new_cstr(mrb, hexdigest); }
/*! \brief Compute SHA384 checksum */ void compute_sha384(char *dst, u_int8_t *src, int src_len) { SHA384_CTX ctx384; char buf[96]; SHA384_Init(&ctx384); SHA384_Update(&ctx384, src, src_len); SHA384_End(&ctx384, buf); strncpy(dst, buf, 96); }
int main(int argc, char **argv) { int kl, l, fd, ac; int quiet = 0, hash = 0; char *av, *file = (char*)0; FILE *IN = (FILE*)0; SHA256_CTX ctx256; SHA384_CTX ctx384; SHA512_CTX ctx512; unsigned char buf[BUFLEN]; SHA256_Init(&ctx256); SHA384_Init(&ctx384); SHA512_Init(&ctx512); /* Read data from STDIN by default */ fd = fileno(stdin); ac = 1; while (ac < argc) { if (*argv[ac] == '-') { av = argv[ac] + 1; if (!strcmp(av, "q")) { quiet = 1; } else if (!strcmp(av, "256")) { hash |= 1; } else if (!strcmp(av, "384")) { hash |= 2; } else if (!strcmp(av, "512")) { hash |= 4; } else if (!strcmp(av, "ALL")) { hash = 7; } else { usage(argv[0], "Invalid option."); } ac++; } else { file = argv[ac++]; if (ac != argc) { usage(argv[0], "Too many arguments."); } if ((IN = fopen(file, "r")) == NULL) { perror(argv[0]); exit(-1); } fd = fileno(IN); } } if (hash == 0) hash = 7; /* Default to ALL */ kl = 0; while ((l = read(fd,buf,BUFLEN)) > 0) { kl += l; SHA256_Update(&ctx256, (unsigned char*)buf, l); SHA384_Update(&ctx384, (unsigned char*)buf, l); SHA512_Update(&ctx512, (unsigned char*)buf, l); } if (file) { fclose(IN); } if (hash & 1) { SHA256_End(&ctx256, buf); if (!quiet) printf("SHA-256 (%s) = ", file); printf("%s\n", buf); } if (hash & 2) { SHA384_End(&ctx384, buf); if (!quiet) printf("SHA-384 (%s) = ", file); printf("%s\n", buf); } if (hash & 4) { SHA512_End(&ctx512, buf); if (!quiet) printf("SHA-512 (%s) = ", file); printf("%s\n", buf); } return 1; }