Re: git: c7a8e8d372b2 - main - xinstall: make md5 and ripemd160 conditional
Date: Wed, 03 Aug 2022 20:18:56 UTC
Can we also make SHA1 optional too?
On Wed, Aug 3, 2022 at 12:25 PM Dag-Erling Smørgrav <des@freebsd.org> wrote:
> The branch main has been updated by des:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=c7a8e8d372b212c97dde6ce2731db27aa0b2201c
>
> commit c7a8e8d372b212c97dde6ce2731db27aa0b2201c
> Author: Dag-Erling Smørgrav <des@FreeBSD.org>
> AuthorDate: 2022-08-03 19:20:47 +0000
> Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
> CommitDate: 2022-08-03 19:24:07 +0000
>
> xinstall: make md5 and ripemd160 conditional
>
> Sponsored by: Klara, Inc.
> ---
> usr.bin/xinstall/Makefile | 3 ++-
> usr.bin/xinstall/xinstall.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/usr.bin/xinstall/Makefile b/usr.bin/xinstall/Makefile
> index ce70cb882190..9969ef104e98 100644
> --- a/usr.bin/xinstall/Makefile
> +++ b/usr.bin/xinstall/Makefile
> @@ -14,7 +14,8 @@ MAN= install.1
> CFLAGS+= -I${SRCTOP}/contrib/mtree
> CFLAGS+= -I${SRCTOP}/lib/libnetbsd
>
> -LIBADD= md
> +LIBADD= md
> +CFLAGS+= -DWITH_MD5 -DWITH_RIPEMD160
>
> HAS_TESTS=
> SUBDIR.${MK_TESTS}+= tests
> diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
> index ddad7ba9115e..a236838c8fd1 100644
> --- a/usr.bin/xinstall/xinstall.c
> +++ b/usr.bin/xinstall/xinstall.c
> @@ -57,10 +57,14 @@ __FBSDID("$FreeBSD$");
> #include <fcntl.h>
> #include <grp.h>
> #include <libgen.h>
> +#ifdef WITH_MD5
> #include <md5.h>
> +#endif
> #include <paths.h>
> #include <pwd.h>
> +#ifdef WITH_RIPEMD160
> #include <ripemd.h>
> +#endif
> #include <sha.h>
> #include <sha256.h>
> #include <sha512.h>
> @@ -100,8 +104,12 @@ __FBSDID("$FreeBSD$");
> #define BACKUP_SUFFIX ".old"
>
> typedef union {
> +#ifdef WITH_MD5
> MD5_CTX MD5;
> +#endif
> +#ifdef WITH_RIPEMD160
> RIPEMD160_CTX RIPEMD160;
> +#endif
> SHA1_CTX SHA1;
> SHA256_CTX SHA256;
> SHA512_CTX SHA512;
> @@ -109,8 +117,12 @@ typedef union {
>
> static enum {
> DIGEST_NONE = 0,
> +#ifdef WITH_MD5
> DIGEST_MD5,
> +#endif
> +#ifdef WITH_RIPEMD160
> DIGEST_RIPEMD160,
> +#endif
> DIGEST_SHA1,
> DIGEST_SHA256,
> DIGEST_SHA512,
> @@ -288,10 +300,14 @@ main(int argc, char *argv[])
> if (digest != NULL) {
> if (strcmp(digest, "none") == 0) {
> digesttype = DIGEST_NONE;
> +#ifdef WITH_MD5
> } else if (strcmp(digest, "md5") == 0) {
> digesttype = DIGEST_MD5;
> +#endif
> +#ifdef WITH_RIPEMD160
> } else if (strcmp(digest, "rmd160") == 0) {
> digesttype = DIGEST_RIPEMD160;
> +#endif
> } else if (strcmp(digest, "sha1") == 0) {
> digesttype = DIGEST_SHA1;
> } else if (strcmp(digest, "sha256") == 0) {
> @@ -402,10 +418,14 @@ digest_file(const char *name)
> {
>
> switch (digesttype) {
> +#ifdef WITH_MD5
> case DIGEST_MD5:
> return (MD5File(name, NULL));
> +#endif
> +#ifdef WITH_RIPEMD160
> case DIGEST_RIPEMD160:
> return (RIPEMD160_File(name, NULL));
> +#endif
> case DIGEST_SHA1:
> return (SHA1_File(name, NULL));
> case DIGEST_SHA256:
> @@ -424,12 +444,16 @@ digest_init(DIGEST_CTX *c)
> switch (digesttype) {
> case DIGEST_NONE:
> break;
> +#ifdef WITH_MD5
> case DIGEST_MD5:
> MD5Init(&(c->MD5));
> break;
> +#endif
> +#ifdef WITH_RIPEMD160
> case DIGEST_RIPEMD160:
> RIPEMD160_Init(&(c->RIPEMD160));
> break;
> +#endif
> case DIGEST_SHA1:
> SHA1_Init(&(c->SHA1));
> break;
> @@ -449,12 +473,16 @@ digest_update(DIGEST_CTX *c, const char *data,
> size_t len)
> switch (digesttype) {
> case DIGEST_NONE:
> break;
> +#ifdef WITH_MD5
> case DIGEST_MD5:
> MD5Update(&(c->MD5), data, len);
> break;
> +#endif
> +#ifdef WITH_RIPEMD160
> case DIGEST_RIPEMD160:
> RIPEMD160_Update(&(c->RIPEMD160), data, len);
> break;
> +#endif
> case DIGEST_SHA1:
> SHA1_Update(&(c->SHA1), data, len);
> break;
> @@ -472,10 +500,14 @@ digest_end(DIGEST_CTX *c, char *buf)
> {
>
> switch (digesttype) {
> +#ifdef WITH_MD5
> case DIGEST_MD5:
> return (MD5End(&(c->MD5), buf));
> +#endif
> +#ifdef WITH_RIPEMD160
> case DIGEST_RIPEMD160:
> return (RIPEMD160_End(&(c->RIPEMD160), buf));
> +#endif
> case DIGEST_SHA1:
> return (SHA1_End(&(c->SHA1), buf));
> case DIGEST_SHA256:
>