From 0f97a12112bf748474662080848f75804a8fddc4 Mon Sep 17 00:00:00 2001 From: Rob Percival Date: Mon, 29 Feb 2016 20:26:36 +0000 Subject: [PATCH] Move macros for reading/writing integers into ct_locl.h Reviewed-by: Ben Laurie Reviewed-by: Rich Salz --- crypto/ct/ct_b64.c | 9 +-------- crypto/ct/ct_locl.h | 32 ++++++++++++++++++++++++++++++++ crypto/ct/ct_vfy.c | 28 ---------------------------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/crypto/ct/ct_b64.c b/crypto/ct/ct_b64.c index 8228f3d6be..a1693a6c28 100644 --- a/crypto/ct/ct_b64.c +++ b/crypto/ct/ct_b64.c @@ -63,14 +63,7 @@ #include #include -/* - * TODO(robpercival): These macros are getting duplicated all over the place. - * Is there a single place they should be defined for re-use? - * Also, is there a good reason they aren't functions? - */ -#define n2s(c,s) ((s=(((unsigned int)((c)[0]))<<8) | \ - (((unsigned int)((c)[1])))), \ - c+=2) +#include "ct_locl.h" /* * Decodes the base64 string |in| into |out|. diff --git a/crypto/ct/ct_locl.h b/crypto/ct/ct_locl.h index 9409b01a30..fce234da78 100644 --- a/crypto/ct/ct_locl.h +++ b/crypto/ct/ct_locl.h @@ -68,6 +68,38 @@ # define MAX_SCT_SIZE 65535 # define MAX_SCT_LIST_SIZE MAX_SCT_SIZE +/* + * Macros to read and write integers in network-byte order. + */ + +#define n2s(c,s) ((s=(((unsigned int)((c)[0]))<< 8)| \ + (((unsigned int)((c)[1])) )),c+=2) + +#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \ + c[1]=(unsigned char)(((s) )&0xff)),c+=2) + +#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \ + c[1]=(unsigned char)(((l)>> 8)&0xff), \ + c[2]=(unsigned char)(((l) )&0xff)),c+=3) + +#define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \ + l|=((uint64_t)(*((c)++)))<<48, \ + l|=((uint64_t)(*((c)++)))<<40, \ + l|=((uint64_t)(*((c)++)))<<32, \ + l|=((uint64_t)(*((c)++)))<<24, \ + l|=((uint64_t)(*((c)++)))<<16, \ + l|=((uint64_t)(*((c)++)))<< 8, \ + l|=((uint64_t)(*((c)++)))) + +#define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \ + *((c)++)=(unsigned char)(((l)>>48)&0xff), \ + *((c)++)=(unsigned char)(((l)>>40)&0xff), \ + *((c)++)=(unsigned char)(((l)>>32)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff)) + /* Signed Certificate Timestamp */ struct sct_st { sct_version_t version; diff --git a/crypto/ct/ct_vfy.c b/crypto/ct/ct_vfy.c index 27f9e23a8d..57053120ad 100644 --- a/crypto/ct/ct_vfy.c +++ b/crypto/ct/ct_vfy.c @@ -65,34 +65,6 @@ #include "ct_locl.h" -#define n2s(c,s) ((s=(((unsigned int)((c)[0]))<< 8)| \ - (((unsigned int)((c)[1])) )),c+=2) - -#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \ - c[1]=(unsigned char)(((s) )&0xff)),c+=2) - -#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \ - c[1]=(unsigned char)(((l)>> 8)&0xff), \ - c[2]=(unsigned char)(((l) )&0xff)),c+=3) - -#define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \ - l|=((uint64_t)(*((c)++)))<<48, \ - l|=((uint64_t)(*((c)++)))<<40, \ - l|=((uint64_t)(*((c)++)))<<32, \ - l|=((uint64_t)(*((c)++)))<<24, \ - l|=((uint64_t)(*((c)++)))<<16, \ - l|=((uint64_t)(*((c)++)))<< 8, \ - l|=((uint64_t)(*((c)++)))) - -#define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \ - *((c)++)=(unsigned char)(((l)>>48)&0xff), \ - *((c)++)=(unsigned char)(((l)>>40)&0xff), \ - *((c)++)=(unsigned char)(((l)>>32)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff)) - typedef enum sct_signature_type_t { SIGNATURE_TYPE_NOT_SET = -1, SIGNATURE_TYPE_CERT_TIMESTAMP, -- 2.40.0