/** Get the sha256 sum of file. * @param filename name of the file * @return the checksum on success, NULL on error * @addtogroup alpm_misc */ char SYMEXPORT *alpm_compute_sha256sum(const char *filename) { unsigned char output[32]; ASSERT(filename != NULL, return NULL); /* defined above for OpenSSL, otherwise defined in sha2.h */ if(sha2_file(filename, output, 0) > 0) { return NULL; } return hex_representation(output, 32); }
/** Get the md5 sum of file. * @param filename name of the file * @return the checksum on success, NULL on error * @addtogroup alpm_misc */ char SYMEXPORT *alpm_compute_md5sum(const char *filename) { unsigned char output[16]; ASSERT(filename != NULL, return NULL); /* defined above for OpenSSL, otherwise defined in md5.h */ if(md5_file(filename, output) > 0) { return NULL; } return hex_representation(output, 16); }
static char *sha2_fd(int fd) { SHA256_CTX ctx; unsigned char buf[BUFSIZ], output[32]; ssize_t n; SHA256_Init(&ctx); while ((n = read(fd, buf, sizeof(buf))) > 0 || errno == EINTR) { if (n < 0) continue; SHA256_Update(&ctx, buf, n); } if (n < 0) return NULL; SHA256_Final(output, &ctx); return hex_representation(output, 32); }
static char *md5_fd(int fd) { MD5_CTX ctx; unsigned char buf[BUFSIZ], output[16]; ssize_t n; MD5_Init(&ctx); while ((n = read(fd, buf, sizeof(buf))) > 0 || errno == EINTR) { if (n < 0) continue; MD5_Update(&ctx, buf, n); } if (n < 0) return NULL; MD5_Final(output, &ctx); return hex_representation(output, 16); }
string Z3BitVector::internal_representation(int in, string type){ return hex_representation(in, type); }