[Cryptography] [patch chacha20_drng 3/4] API: Remove version macros

Jason Cooper cryptography at lakedaemon.net
Fri Aug 5 15:21:54 EDT 2016


From: Jason Cooper <jason at lakedaemon.net>

It's no fun maintaining and supporting more than one way to do the same
thing.  Let's head this off before it bites us.  Users should be using
_versionstring and _version to retrieve this information.

While updating the Makefile for this change, simplify it.

Signed-off-by: Jason Cooper <jason at lakedaemon.net>
---
 Makefile        |  6 +++---
 chacha20_drng.c | 22 ++++++++++++++++++----
 chacha20_drng.h | 14 --------------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 8cf17ce49001..0624df589408 100644
--- a/Makefile
+++ b/Makefile
@@ -14,9 +14,9 @@ PREFIX := /usr/local
 LIBDIR := lib
 
 NAME := chacha20_drng
-LIBMAJOR=$(shell cat chacha20_drng.h | grep define | grep MAJVERSION | awk '{print $$3}')
-LIBMINOR=$(shell cat chacha20_drng.h | grep define | grep MINVERSION | awk '{print $$3}')
-LIBPATCH=$(shell cat chacha20_drng.h | grep define | grep PATCHLEVEL | awk '{print $$3}')
+LIBMAJOR=$(shell grep '^\#define[ \t]*MAJVERSION' chacha20_drng.c | awk '{print $$3}')
+LIBMINOR=$(shell grep '^\#define[ \t]*MINVERSION' chacha20_drng.c | awk '{print $$3}')
+LIBPATCH=$(shell grep '^\#define[ \t]*PATCHLEVEL' chacha20_drng.c | awk '{print $$3}')
 LIBVERSION := $(LIBMAJOR).$(LIBMINOR).$(LIBPATCH)
 C_SRCS := chacha20_drng.c
 JENT_OBJS:=
diff --git a/chacha20_drng.c b/chacha20_drng.c
index 0b3b1230bd4f..468909042abb 100644
--- a/chacha20_drng.c
+++ b/chacha20_drng.c
@@ -46,6 +46,20 @@
 
 #include "chacha20_drng.h"
 
+#define MAJVERSION 1   /* API / ABI incompatible changes,
+			* functional changes that require consumer
+			* to be updated (as long as this number is
+			* zero, the API is not considered stable
+			* and can change without a bump of the
+			* major version). */
+#define MINVERSION 1   /* API compatible, ABI may change,
+			* functional enhancements only, consumer
+			* can be left unchanged if enhancements are
+			* not considered. */
+#define PATCHLEVEL 0   /* API / ABI compatible, no functional
+			* changes, no enhancements, bug fixes
+			* only. */
+
 #define CHACHA20_DRNG_ALIGNMENT	8	/* allow u8 to u32 conversions */
 
 /*********************************** Helper ***********************************/
@@ -591,16 +605,16 @@ int drng_chacha20_get(struct chacha20_drng *drng, uint8_t *outbuf,
 void drng_chacha20_versionstring(char *buf, uint32_t buflen)
 {
 	snprintf(buf, buflen, "ChaCha20 DRNG %d.%d.%d",
-		 DRNG_CHACHA20_MAJVERSION, DRNG_CHACHA20_MINVERSION, DRNG_CHACHA20_PATCHLEVEL);
+		 MAJVERSION, MINVERSION, PATCHLEVEL);
 }
 
 uint32_t drng_chacha20_version(void)
 {
 	uint32_t version = 0;
 
-	version =  DRNG_CHACHA20_MAJVERSION * 1000000;
-	version += DRNG_CHACHA20_MINVERSION * 10000;
-	version += DRNG_CHACHA20_PATCHLEVEL * 100;
+	version =  MAJVERSION * 1000000;
+	version += MINVERSION * 10000;
+	version += PATCHLEVEL * 100;
 
 	return version;
 }
diff --git a/chacha20_drng.h b/chacha20_drng.h
index 275cbdb47110..3116731339af 100644
--- a/chacha20_drng.h
+++ b/chacha20_drng.h
@@ -44,20 +44,6 @@ extern "C"
 
 #include <stdint.h>
 
-#define DRNG_CHACHA20_MAJVERSION 1  /* API / ABI incompatible changes,
-				     * functional changes that require consumer
-				     * to be updated (as long as this number is
-				     * zero, the API is not considered stable
-				     * and can change without a bump of the
-				     * major version). */
-#define DRNG_CHACHA20_MINVERSION 1  /* API compatible, ABI may change,
-				     * functional enhancements only, consumer
-				     * can be left unchanged if enhancements are
-				     * not considered. */
-#define DRNG_CHACHA20_PATCHLEVEL 0  /* API / ABI compatible, no functional
-				     * changes, no enhancements, bug fixes
-				     * only. */
-
 #if __GNUC__ >= 4
 # define DSO_PUBLIC __attribute__ ((visibility ("default")))
 #else
-- 
2.9.2



More information about the cryptography mailing list