diff --git a/src/headers/tomcrypt_macros.h b/src/headers/tomcrypt_macros.h index 94aa7c32..257f5238 100644 --- a/src/headers/tomcrypt_macros.h +++ b/src/headers/tomcrypt_macros.h @@ -1,6 +1,11 @@ /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ + +#define LTC_TMPVAR__(n, l) n ## l +#define LTC_TMPVAR_(n, l) LTC_TMPVAR__(n, l) +#define LTC_TMPVAR(n) LTC_TMPVAR_(LTC_ ## n ## _, __LINE__) + /* ---- HELPER MACROS ---- */ #ifdef ENDIAN_NEUTRAL @@ -275,20 +280,20 @@ static inline ulong32 ROR(ulong32 word, int i) #ifndef LTC_NO_ROLC #define ROLc(word,i) ({ \ - ulong32 ROLc_tmp = (word); \ + ulong32 LTC_TMPVAR(ROLc) = (word); \ __asm__ ("roll %2, %0" : \ - "=r" (ROLc_tmp) : \ - "0" (ROLc_tmp), \ + "=r" (LTC_TMPVAR(ROLc)) : \ + "0" (LTC_TMPVAR(ROLc)), \ "I" (i)); \ - ROLc_tmp; \ + LTC_TMPVAR(ROLc); \ }) #define RORc(word,i) ({ \ - ulong32 RORc_tmp = (word); \ + ulong32 LTC_TMPVAR(RORc) = (word); \ __asm__ ("rorl %2, %0" : \ - "=r" (RORc_tmp) : \ - "0" (RORc_tmp), \ + "=r" (LTC_TMPVAR(RORc)) : \ + "0" (LTC_TMPVAR(RORc)), \ "I" (i)); \ - RORc_tmp; \ + LTC_TMPVAR(RORc); \ }) #else @@ -393,20 +398,20 @@ static inline ulong64 ROR64(ulong64 word, int i) #ifndef LTC_NO_ROLC #define ROL64c(word,i) ({ \ - ulong64 ROL64c_tmp = word; \ + ulong64 LTC_TMPVAR(ROL64c) = word; \ __asm__ ("rolq %2, %0" : \ - "=r" (ROL64c_tmp) : \ - "0" (ROL64c_tmp), \ + "=r" (LTC_TMPVAR(ROL64c)) : \ + "0" (LTC_TMPVAR(ROL64c)), \ "J" (i)); \ - ROL64c_tmp; \ + LTC_TMPVAR(ROL64c); \ }) #define ROR64c(word,i) ({ \ - ulong64 ROR64c_tmp = word; \ + ulong64 LTC_TMPVAR(ROR64c) = word; \ __asm__ ("rorq %2, %0" : \ - "=r" (ROR64c_tmp) : \ - "0" (ROR64c_tmp), \ + "=r" (LTC_TMPVAR(ROR64c)) : \ + "0" (LTC_TMPVAR(ROR64c)), \ "J" (i)); \ - ROR64c_tmp; \ + LTC_TMPVAR(ROR64c); \ }) #else /* LTC_NO_ROLC */ diff --git a/src/headers/tomcrypt_pk.h b/src/headers/tomcrypt_pk.h index 132fc74c..903e118d 100644 --- a/src/headers/tomcrypt_pk.h +++ b/src/headers/tomcrypt_pk.h @@ -548,43 +548,43 @@ typedef struct ltc_asn1_list_ { struct ltc_asn1_list_ *prev, *next, *child, *parent; } ltc_asn1_list; -#define LTC_SET_ASN1(list, index, Type, Data, Size) \ - do { \ - int LTC_MACRO_temp = (index); \ - ltc_asn1_list *LTC_MACRO_list = (list); \ - LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \ - LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \ - LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \ - LTC_MACRO_list[LTC_MACRO_temp].used = 0; \ - LTC_MACRO_list[LTC_MACRO_temp].optional = 0; \ - LTC_MACRO_list[LTC_MACRO_temp].klass = 0; \ - LTC_MACRO_list[LTC_MACRO_temp].pc = 0; \ - LTC_MACRO_list[LTC_MACRO_temp].tag = 0; \ +#define LTC_SET_ASN1(list, index, Type, Data, Size) \ + do { \ + int LTC_TMPVAR(SA) = (index); \ + ltc_asn1_list *LTC_TMPVAR(SA_list) = (list); \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].type = (Type); \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].data = (void*)(Data); \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].size = (Size); \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].used = 0; \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].optional = 0; \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].klass = 0; \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].pc = 0; \ + LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].tag = 0; \ } while (0) -#define LTC_SET_ASN1_IDENTIFIER(list, index, Class, Pc, Tag) \ - do { \ - int LTC_MACRO_temp = (index); \ - ltc_asn1_list *LTC_MACRO_list = (list); \ - LTC_MACRO_list[LTC_MACRO_temp].type = LTC_ASN1_CUSTOM_TYPE; \ - LTC_MACRO_list[LTC_MACRO_temp].klass = (Class); \ - LTC_MACRO_list[LTC_MACRO_temp].pc = (Pc); \ - LTC_MACRO_list[LTC_MACRO_temp].tag = (Tag); \ +#define LTC_SET_ASN1_IDENTIFIER(list, index, Class, Pc, Tag) \ + do { \ + int LTC_TMPVAR(SAI) = (index); \ + ltc_asn1_list *LTC_TMPVAR(SAI_list) = (list); \ + LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].type = LTC_ASN1_CUSTOM_TYPE; \ + LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].klass = (Class); \ + LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].pc = (Pc); \ + LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].tag = (Tag); \ } while (0) -#define LTC_SET_ASN1_CUSTOM_CONSTRUCTED(list, index, Class, Tag, Data) \ - do { \ - int LTC_MACRO_temp##__LINE__ = (index); \ - LTC_SET_ASN1(list, LTC_MACRO_temp##__LINE__, LTC_ASN1_CUSTOM_TYPE, Data, 1); \ - LTC_SET_ASN1_IDENTIFIER(list, LTC_MACRO_temp##__LINE__, Class, LTC_ASN1_PC_CONSTRUCTED, Tag); \ +#define LTC_SET_ASN1_CUSTOM_CONSTRUCTED(list, index, Class, Tag, Data) \ + do { \ + int LTC_TMPVAR(SACC) = (index); \ + LTC_SET_ASN1(list, LTC_TMPVAR(SACC), LTC_ASN1_CUSTOM_TYPE, Data, 1); \ + LTC_SET_ASN1_IDENTIFIER(list, LTC_TMPVAR(SACC), Class, LTC_ASN1_PC_CONSTRUCTED, Tag); \ } while (0) -#define LTC_SET_ASN1_CUSTOM_PRIMITIVE(list, index, Class, Tag, Type, Data, Size) \ - do { \ - int LTC_MACRO_temp##__LINE__ = (index); \ - LTC_SET_ASN1(list, LTC_MACRO_temp##__LINE__, LTC_ASN1_CUSTOM_TYPE, Data, Size); \ - LTC_SET_ASN1_IDENTIFIER(list, LTC_MACRO_temp##__LINE__, Class, LTC_ASN1_PC_PRIMITIVE, Tag); \ - list[LTC_MACRO_temp##__LINE__].used = (int)(Type); \ +#define LTC_SET_ASN1_CUSTOM_PRIMITIVE(list, index, Class, Tag, Type, Data, Size) \ + do { \ + int LTC_TMPVAR(SACP) = (index); \ + LTC_SET_ASN1(list, LTC_TMPVAR(SACP), LTC_ASN1_CUSTOM_TYPE, Data, Size); \ + LTC_SET_ASN1_IDENTIFIER(list, LTC_TMPVAR(SACP), Class, LTC_ASN1_PC_PRIMITIVE, Tag); \ + list[LTC_TMPVAR(SACP)].used = (int)(Type); \ } while (0) extern const char* der_asn1_class_to_string_map[];