lobase

Linux port of OpenBSDs userland.
Log | Files | Refs | README

commit 1306d269624c43174ac8973e1b761bf5079a93ce
parent 3b6e9d7b33d9af78ed75d566c78d01df81da9995
Author: Duncaen <mail@duncano.de>
Date:   Mon,  6 Mar 2017 23:29:52 +0100

lib/libopenbsd: remove hash generated hash helpers

Diffstat:
lib/libopenbsd/hash/md5hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/rmd160hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/sha1hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/sha224hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/sha256hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/sha384hl.c | 113-------------------------------------------------------------------------------
lib/libopenbsd/hash/sha512hl.c | 113-------------------------------------------------------------------------------
7 files changed, 0 insertions(+), 791 deletions(-)

diff --git a/lib/libopenbsd/hash/md5hl.c b/lib/libopenbsd/hash/md5hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <md5.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -MD5End(MD5_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[MD5_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(MD5_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - MD5Final(digest, ctx); - for (i = 0; i < MD5_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(MD5End); - -char * -MD5FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - MD5_CTX ctx; - int fd, save_errno; - ssize_t nr; - - MD5Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - MD5Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : MD5End(&ctx, buf)); -} -DEF_WEAK(MD5FileChunk); - -char * -MD5File(const char *filename, char *buf) -{ - return (MD5FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(MD5File); - -char * -MD5Data(const u_char *data, size_t len, char *buf) -{ - MD5_CTX ctx; - - MD5Init(&ctx); - MD5Update(&ctx, data, len); - return (MD5End(&ctx, buf)); -} -DEF_WEAK(MD5Data); diff --git a/lib/libopenbsd/hash/rmd160hl.c b/lib/libopenbsd/hash/rmd160hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <rmd160.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -RMD160End(RMD160_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[RMD160_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(RMD160_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - RMD160Final(digest, ctx); - for (i = 0; i < RMD160_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(RMD160End); - -char * -RMD160FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - RMD160_CTX ctx; - int fd, save_errno; - ssize_t nr; - - RMD160Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - RMD160Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : RMD160End(&ctx, buf)); -} -DEF_WEAK(RMD160FileChunk); - -char * -RMD160File(const char *filename, char *buf) -{ - return (RMD160FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(RMD160File); - -char * -RMD160Data(const u_char *data, size_t len, char *buf) -{ - RMD160_CTX ctx; - - RMD160Init(&ctx); - RMD160Update(&ctx, data, len); - return (RMD160End(&ctx, buf)); -} -DEF_WEAK(RMD160Data); diff --git a/lib/libopenbsd/hash/sha1hl.c b/lib/libopenbsd/hash/sha1hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sha1.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -SHA1End(SHA1_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[SHA1_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(SHA1_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - SHA1Final(digest, ctx); - for (i = 0; i < SHA1_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(SHA1End); - -char * -SHA1FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - SHA1_CTX ctx; - int fd, save_errno; - ssize_t nr; - - SHA1Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - SHA1Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : SHA1End(&ctx, buf)); -} -DEF_WEAK(SHA1FileChunk); - -char * -SHA1File(const char *filename, char *buf) -{ - return (SHA1FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(SHA1File); - -char * -SHA1Data(const u_char *data, size_t len, char *buf) -{ - SHA1_CTX ctx; - - SHA1Init(&ctx); - SHA1Update(&ctx, data, len); - return (SHA1End(&ctx, buf)); -} -DEF_WEAK(SHA1Data); diff --git a/lib/libopenbsd/hash/sha224hl.c b/lib/libopenbsd/hash/sha224hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sha2.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -SHA224End(SHA2_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[SHA224_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(SHA224_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - SHA224Final(digest, ctx); - for (i = 0; i < SHA224_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(SHA224End); - -char * -SHA224FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - SHA2_CTX ctx; - int fd, save_errno; - ssize_t nr; - - SHA224Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - SHA224Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : SHA224End(&ctx, buf)); -} -DEF_WEAK(SHA224FileChunk); - -char * -SHA224File(const char *filename, char *buf) -{ - return (SHA224FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(SHA224File); - -char * -SHA224Data(const u_char *data, size_t len, char *buf) -{ - SHA2_CTX ctx; - - SHA224Init(&ctx); - SHA224Update(&ctx, data, len); - return (SHA224End(&ctx, buf)); -} -DEF_WEAK(SHA224Data); diff --git a/lib/libopenbsd/hash/sha256hl.c b/lib/libopenbsd/hash/sha256hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sha2.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -SHA256End(SHA2_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[SHA256_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(SHA256_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - SHA256Final(digest, ctx); - for (i = 0; i < SHA256_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(SHA256End); - -char * -SHA256FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - SHA2_CTX ctx; - int fd, save_errno; - ssize_t nr; - - SHA256Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - SHA256Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : SHA256End(&ctx, buf)); -} -DEF_WEAK(SHA256FileChunk); - -char * -SHA256File(const char *filename, char *buf) -{ - return (SHA256FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(SHA256File); - -char * -SHA256Data(const u_char *data, size_t len, char *buf) -{ - SHA2_CTX ctx; - - SHA256Init(&ctx); - SHA256Update(&ctx, data, len); - return (SHA256End(&ctx, buf)); -} -DEF_WEAK(SHA256Data); diff --git a/lib/libopenbsd/hash/sha384hl.c b/lib/libopenbsd/hash/sha384hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sha2.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -SHA384End(SHA2_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[SHA384_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(SHA384_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - SHA384Final(digest, ctx); - for (i = 0; i < SHA384_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(SHA384End); - -char * -SHA384FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - SHA2_CTX ctx; - int fd, save_errno; - ssize_t nr; - - SHA384Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - SHA384Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : SHA384End(&ctx, buf)); -} -DEF_WEAK(SHA384FileChunk); - -char * -SHA384File(const char *filename, char *buf) -{ - return (SHA384FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(SHA384File); - -char * -SHA384Data(const u_char *data, size_t len, char *buf) -{ - SHA2_CTX ctx; - - SHA384Init(&ctx); - SHA384Update(&ctx, data, len); - return (SHA384End(&ctx, buf)); -} -DEF_WEAK(SHA384Data); diff --git a/lib/libopenbsd/hash/sha512hl.c b/lib/libopenbsd/hash/sha512hl.c @@ -1,113 +0,0 @@ -/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */ - -/* - * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * If we meet some day, and you think this stuff is worth it, you - * can buy me a beer in return. Poul-Henning Kamp - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#include <sha2.h> - -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) - -char * -SHA512End(SHA2_CTX *ctx, char *buf) -{ - int i; - u_int8_t digest[SHA512_DIGEST_LENGTH]; - static const char hex[] = "0123456789abcdef"; - - if (buf == NULL && (buf = malloc(SHA512_DIGEST_STRING_LENGTH)) == NULL) - return (NULL); - - SHA512Final(digest, ctx); - for (i = 0; i < SHA512_DIGEST_LENGTH; i++) { - buf[i + i] = hex[digest[i] >> 4]; - buf[i + i + 1] = hex[digest[i] & 0x0f]; - } - buf[i + i] = '\0'; - explicit_bzero(digest, sizeof(digest)); - return (buf); -} -DEF_WEAK(SHA512End); - -char * -SHA512FileChunk(const char *filename, char *buf, off_t off, off_t len) -{ - struct stat sb; - u_char buffer[BUFSIZ]; - SHA2_CTX ctx; - int fd, save_errno; - ssize_t nr; - - SHA512Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (NULL); - if (len == 0) { - if (fstat(fd, &sb) == -1) { - close(fd); - return (NULL); - } - len = sb.st_size; - } - if (off > 0 && lseek(fd, off, SEEK_SET) < 0) { - close(fd); - return (NULL); - } - - while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) { - SHA512Update(&ctx, buffer, (size_t)nr); - if (len > 0 && (len -= nr) == 0) - break; - } - - save_errno = errno; - close(fd); - errno = save_errno; - return (nr < 0 ? NULL : SHA512End(&ctx, buf)); -} -DEF_WEAK(SHA512FileChunk); - -char * -SHA512File(const char *filename, char *buf) -{ - return (SHA512FileChunk(filename, buf, (off_t)0, (off_t)0)); -} -DEF_WEAK(SHA512File); - -char * -SHA512Data(const u_char *data, size_t len, char *buf) -{ - SHA2_CTX ctx; - - SHA512Init(&ctx); - SHA512Update(&ctx, data, len); - return (SHA512End(&ctx, buf)); -} -DEF_WEAK(SHA512Data);