aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-18 17:54:49 +0100
committerMattias Andrée <maandree@kth.se>2022-01-18 17:54:49 +0100
commitedb70e343f3000dfef1f38583e88e74d1e71d804 (patch)
tree9c900264882428578bba81748c3a773faec6ebc0
parentFix typo: libar2_earse -> libar2_erase (diff)
downloadlibar2-edb70e343f3000dfef1f38583e88e74d1e71d804.tar.gz
libar2-edb70e343f3000dfef1f38583e88e74d1e71d804.tar.bz2
libar2-edb70e343f3000dfef1f38583e88e74d1e71d804.tar.xz
Improve portability
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libar2.h28
-rw-r--r--libar2_encode_params.c8
-rw-r--r--libar2_erase.c3
-rw-r--r--mk/windows.mk2
4 files changed, 35 insertions, 6 deletions
diff --git a/libar2.h b/libar2.h
index 835a02f..862723f 100644
--- a/libar2.h
+++ b/libar2.h
@@ -7,6 +7,22 @@
/* for internal use { */
+#ifndef LIBAR2_PUBLIC__
+# if defined(_MSC_VER)
+# define LIBAR2_PUBLIC__ __declspec(dllexport)
+# else
+# define LIBAR2_PUBLIC__
+# endif
+#endif
+
+#ifndef LIBAR2_PUBLIC_VARIABLE__
+# if defined(_MSC_VER)
+# define LIBAR2_PUBLIC_VARIABLE__ __declspec(dllexport)
+# else
+# define LIBAR2_PUBLIC_VARIABLE__
+# endif
+#endif
+
#if defined(UINT_LEAST32_C)
# define LIBAR2_UINT_LEAST32_C__(V) UINT_LEAST32_C(V)
#elif defined(UINT32_C)
@@ -446,6 +462,7 @@ extern enum libar2_argon2_version libar2_latest_argon2_version;
* @return String representing the type, `NULL` (with `errno`
* set to EINVAL) if either argument is invalid
*/
+LIBAR2_PUBLIC__
const char *libar2_type_to_string(enum libar2_argon2_type type, enum libar2_casing casing);
/**
@@ -455,6 +472,7 @@ const char *libar2_type_to_string(enum libar2_argon2_type type, enum libar2_casi
* @param typep Output parameter for the primitive type
* @return 0 on success, -1 (with `errno` set to EINVAL) if `str` is invalid
*/
+LIBAR2_PUBLIC__
int libar2_string_to_type(const char *str, enum libar2_argon2_type *typep);
/**
@@ -465,6 +483,7 @@ int libar2_string_to_type(const char *str, enum libar2_argon2_type *typep);
* @return String representing the version, `NULL` (with
* `errno` set to EINVAL) if `version` is invalid
*/
+LIBAR2_PUBLIC__
const char *libar2_version_to_string(enum libar2_argon2_version version);
/**
@@ -475,6 +494,7 @@ const char *libar2_version_to_string(enum libar2_argon2_version version);
* @return String representing the version, `NULL` (with
* `errno` set to EINVAL) if `version` is invalid
*/
+LIBAR2_PUBLIC__
const char *libar2_version_to_string_proper(enum libar2_argon2_version version);
/**
@@ -484,6 +504,7 @@ const char *libar2_version_to_string_proper(enum libar2_argon2_version version);
* @param versionp Output parameter for the version number value
* @return 0 on success, -1 (with `errno` set to EINVAL) if `str` is invalid
*/
+LIBAR2_PUBLIC__
int libar2_string_to_version(const char *str, enum libar2_argon2_version *versionp);
/**
@@ -501,6 +522,7 @@ int libar2_string_to_version(const char *str, enum libar2_argon2_version *versio
* @return The number of bytes required for `buf`,
* including the NUL byte added to the end
*/
+LIBAR2_PUBLIC__
size_t libar2_encode_params(char *buf, const struct libar2_argon2_parameters *params);
/**
@@ -515,6 +537,7 @@ size_t libar2_encode_params(char *buf, const struct libar2_argon2_parameters *pa
* @return The number of bytes required for `buf`,
* including the NUL byte added to the end
*/
+LIBAR2_PUBLIC__
size_t libar2_encode_base64(char *buf, const void *data, size_t len);
/**
@@ -550,6 +573,7 @@ size_t libar2_encode_base64(char *buf, const void *data, size_t len);
* a hash, and not just parameters, `&str[return]` will
* point to the hash
*/
+LIBAR2_PUBLIC__
size_t libar2_decode_params(const char *str, struct libar2_argon2_parameters *params, char **bufp, struct libar2_context *ctx);
/**
@@ -560,6 +584,7 @@ size_t libar2_decode_params(const char *str, struct libar2_argon2_parameters *pa
* @param lenp Output parameter for the length of the decoded data
* @return The number of bytes read
*/
+LIBAR2_PUBLIC__
size_t libar2_decode_base64(const char *str, void *data, size_t *lenp);
/**
@@ -569,6 +594,7 @@ size_t libar2_decode_base64(const char *str, void *data, size_t *lenp);
* @param errmsgp Output parameter for the error message, or `null`
* @return The first detected error, or LIBAR2_OK (0) if none
*/
+LIBAR2_PUBLIC__
enum libar2_parameter_error libar2_validate_params(const struct libar2_argon2_parameters *params, const char **errmsgp);
/**
@@ -577,6 +603,7 @@ enum libar2_parameter_error libar2_validate_params(const struct libar2_argon2_pa
* @param mem The memory to erase
* @param size The number of bytes to erase
*/
+LIBAR2_PUBLIC__
void libar2_erase(volatile void *mem, size_t size);
/**
@@ -613,6 +640,7 @@ void libar2_erase(volatile void *mem, size_t size);
* @param ctx Library settings
* @return 0 on success, -1 on failure
*/
+LIBAR2_PUBLIC__
int libar2_hash(void *hash, void *msg, size_t msglen, struct libar2_argon2_parameters *params, struct libar2_context *ctx);
#endif
diff --git a/libar2_encode_params.c b/libar2_encode_params.c
index cdf634a..498de9c 100644
--- a/libar2_encode_params.c
+++ b/libar2_encode_params.c
@@ -8,12 +8,12 @@ libar2_encode_params(char *buf, const struct libar2_argon2_parameters *params)
size_t off;
#define FMT_AND_ARGS\
- "$%s$v=%i$m=%ju,t=%ju,p=%ju$",\
+ "$%s$v=%i$m=%lu,t=%lu,p=%lu$",\
libar2_type_to_string(params->type, LIBAR2_LOWER_CASE),\
(int)params->version,\
- (uintmax_t)params->m_cost,\
- (uintmax_t)params->t_cost,\
- (uintmax_t)params->lanes
+ (unsigned long int)params->m_cost,\
+ (unsigned long int)params->t_cost,\
+ (unsigned long int)params->lanes
if (buf) {
off = (size_t)sprintf(buf, FMT_AND_ARGS);
diff --git a/libar2_erase.c b/libar2_erase.c
index 490cc4a..417842f 100644
--- a/libar2_erase.c
+++ b/libar2_erase.c
@@ -39,9 +39,10 @@ libar2_erase(volatile void *mem_, size_t size)
/* Typo in version 1.0 */
#if defined(__GNUC__)
+LIBAR2_PUBLIC__
extern __typeof(libar2_erase) libar2_earse __attribute__((__weak__, __alias__("libar2_erase")));
#else
-void libar2_earse(volatile void *mem, size_t size);
+LIBAR2_PUBLIC__ void libar2_earse(volatile void *mem, size_t size);
void
libar2_earse(volatile void *mem, size_t size)
{
diff --git a/mk/windows.mk b/mk/windows.mk
index e9602e1..ae6fc0b 100644
--- a/mk/windows.mk
+++ b/mk/windows.mk
@@ -1,4 +1,4 @@
LIBEXT = dll
-LIBFLAGS = -mdll
+LIBFLAGS = -shared
LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
LIBMINOREXT = $(LIB_VERSION).$(LIBEXT)