]> xenbits.xensource.com Git - unikraft/libs/newlib.git/commitdiff
Adapt crypt code to Unikraft
authorCostin Lupu <costin.lupu@cs.pub.ro>
Wed, 27 Nov 2019 14:22:31 +0000 (16:22 +0200)
committerCostin Lupu <costin.lupu@cs.pub.ro>
Wed, 27 Nov 2019 19:26:05 +0000 (21:26 +0200)
We tried to keep the changes of the original code to a minimum. For this
purpose, we used the C preprocessor in order to disable the 'hidden' musl
qualifier. We also had to rename the <crypt.h> header in
`musl-imported/src/include` to <_crypt.h> because, being a private header, we
could not add its directory at the top of the include paths list to include it
before the <crypt.h> header in `musl-imported/include` (the latter being
a public include path).

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
Reviewed-by: Roxana Nicolescu <nicolescu.roxana1996@gmail.com>
Config.uk
Makefile.uk
musl-imported/src/crypt/crypt.c
musl-imported/src/crypt/crypt_r.c
musl-imported/src/include/_crypt.h [new file with mode: 0644]
musl-imported/src/include/crypt.h [deleted file]

index 5b8f467410db0ff5bd4a51df412aba226648667e..ab127f0d39e1f754a77dd4e076fbb4c3b35d2a2c 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -22,4 +22,8 @@ if LIBNEWLIBC
        config LIBNEWLIBC_LINUX_ERRNO_EXTENSIONS
                bool "Use Linux errno extensions"
                default n
+
+       config LIBNEWLIBC_CRYPT
+               bool "Enable crypt() and crypt_r() functions"
+               default y
 endif
index 9eb1f036600fc0e7ed591cb89a0319473c8011c9..17d8d7a50e8d79c630221e9e02199072833d763f 100644 (file)
@@ -68,6 +68,7 @@ LIBNEWLIB_LIBM = $(LIBNEWLIBC_ORIGIN)/$(LIBNEWLIB_SUBDIR)/newlib/libm
 LIBNEWLIBC_COMMON_INCLUDES-y     += -I$(LIBNEWLIBC_BASE)/include
 LIBNEWLIBC_COMMON_INCLUDES-y     += -I$(LIBNEWLIBC_BASE)/musl-imported/include
 LIBNEWLIBC_COMMON_INCLUDES-y     += -I$(LIBNEWLIBC_BASE)/musl-imported/arch/generic
+LIBNEWLIBGLUE_CINCLUDES-y        += -I$(LIBNEWLIBC_BASE)/musl-imported/src/include
 LIBNEWLIBC_COMMON_INCLUDES-$(CONFIG_ARCH_X86_64) += -I$(LIBNEWLIBC_BASE)/musl-imported/arch/x86_64
 LIBNEWLIBC_COMMON_INCLUDES-y     += -I$(LIBNEWLIB_LIBC)/include
 
@@ -132,6 +133,20 @@ LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/misc/syslog.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/termios/tcsetattr.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/termios/tcgetattr.c
 
+ifeq ($(CONFIG_LIBNEWLIBC_CRYPT),y)
+LIBNEWLIBGLUE_CFLAGS-y   += -Wno-missing-braces -Wno-sign-compare -Wno-char-subscripts
+LIBNEWLIBGLUE_CFLAGS-y   += -Dhidden=
+
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_blowfish.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_des.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_md5.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_r.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_sha256.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/crypt_sha512.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/crypt/encrypt.c
+endif
+
 ################################################################################
 # Newlib/libc code -- argz
 ################################################################################
index e6237e397fc757074907fb1684c5cfa14d5083c1..4cad99baf066c8111b4402cc4b0192c4463b0729 100644 (file)
@@ -1,5 +1,5 @@
 #include <unistd.h>
-#include <crypt.h>
+#include <_crypt.h>
 
 char *crypt(const char *key, const char *salt)
 {
index db6015e236f639089cb1b6c4cc65f548b96b56ed..2e93bd7e40de3c1f04a55209eae50fe9c7406449 100644 (file)
@@ -1,4 +1,4 @@
-#include <crypt.h>
+#include <_crypt.h>
 
 char *__crypt_r(const char *key, const char *salt, struct crypt_data *data)
 {
@@ -20,4 +20,8 @@ char *__crypt_r(const char *key, const char *salt, struct crypt_data *data)
        return __crypt_des(key, salt, output);
 }
 
+/* TODO move this to some global header */
+#define weak_alias(old, new) \
+       extern __typeof(old) new __attribute__((__weak__, __alias__(#old)))
+
 weak_alias(__crypt_r, crypt_r);
diff --git a/musl-imported/src/include/_crypt.h b/musl-imported/src/include/_crypt.h
new file mode 100644 (file)
index 0000000..c3dad71
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef CRYPT_H
+#define CRYPT_H
+
+#include "../../include/crypt.h"
+
+/* TODO #include <features.h> */
+
+hidden char *__crypt_r(const char *, const char *, struct crypt_data *);
+
+hidden char *__crypt_des(const char *, const char *, char *);
+hidden char *__crypt_md5(const char *, const char *, char *);
+hidden char *__crypt_blowfish(const char *, const char *, char *);
+hidden char *__crypt_sha256(const char *, const char *, char *);
+hidden char *__crypt_sha512(const char *, const char *, char *);
+
+#endif
diff --git a/musl-imported/src/include/crypt.h b/musl-imported/src/include/crypt.h
deleted file mode 100644 (file)
index f6c6309..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef CRYPT_H
-#define CRYPT_H
-
-#include "../../include/crypt.h"
-
-#include <features.h>
-
-hidden char *__crypt_r(const char *, const char *, struct crypt_data *);
-
-hidden char *__crypt_des(const char *, const char *, char *);
-hidden char *__crypt_md5(const char *, const char *, char *);
-hidden char *__crypt_blowfish(const char *, const char *, char *);
-hidden char *__crypt_sha256(const char *, const char *, char *);
-hidden char *__crypt_sha512(const char *, const char *, char *);
-
-#endif