Skip to content

Commit 0173cac

Browse files
committed
Add LTC_TMPVAR() macro
Use unique names for variables declared in macros. Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 93f5348 commit 0173cac

File tree

2 files changed

+52
-47
lines changed

2 files changed

+52
-47
lines changed

src/headers/tomcrypt_macros.h

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
22
/* SPDX-License-Identifier: Unlicense */
33

4+
5+
#define LTC_TMPVAR__(n, l) n ## l
6+
#define LTC_TMPVAR_(n, l) LTC_TMPVAR__(n, l)
7+
#define LTC_TMPVAR(n) LTC_TMPVAR_(LTC_ ## n ## _, __LINE__)
8+
49
/* ---- HELPER MACROS ---- */
510
#ifdef ENDIAN_NEUTRAL
611

@@ -275,20 +280,20 @@ static inline ulong32 ROR(ulong32 word, int i)
275280
#ifndef LTC_NO_ROLC
276281

277282
#define ROLc(word,i) ({ \
278-
ulong32 ROLc_tmp = (word); \
283+
ulong32 LTC_TMPVAR(ROLc) = (word); \
279284
__asm__ ("roll %2, %0" : \
280-
"=r" (ROLc_tmp) : \
281-
"0" (ROLc_tmp), \
285+
"=r" (LTC_TMPVAR(ROLc)) : \
286+
"0" (LTC_TMPVAR(ROLc)), \
282287
"I" (i)); \
283-
ROLc_tmp; \
288+
LTC_TMPVAR(ROLc); \
284289
})
285290
#define RORc(word,i) ({ \
286-
ulong32 RORc_tmp = (word); \
291+
ulong32 LTC_TMPVAR(RORc) = (word); \
287292
__asm__ ("rorl %2, %0" : \
288-
"=r" (RORc_tmp) : \
289-
"0" (RORc_tmp), \
293+
"=r" (LTC_TMPVAR(RORc)) : \
294+
"0" (LTC_TMPVAR(RORc)), \
290295
"I" (i)); \
291-
RORc_tmp; \
296+
LTC_TMPVAR(RORc); \
292297
})
293298

294299
#else
@@ -393,20 +398,20 @@ static inline ulong64 ROR64(ulong64 word, int i)
393398
#ifndef LTC_NO_ROLC
394399

395400
#define ROL64c(word,i) ({ \
396-
ulong64 ROL64c_tmp = word; \
401+
ulong64 LTC_TMPVAR(ROL64c) = word; \
397402
__asm__ ("rolq %2, %0" : \
398-
"=r" (ROL64c_tmp) : \
399-
"0" (ROL64c_tmp), \
403+
"=r" (LTC_TMPVAR(ROL64c)) : \
404+
"0" (LTC_TMPVAR(ROL64c)), \
400405
"J" (i)); \
401-
ROL64c_tmp; \
406+
LTC_TMPVAR(ROL64c); \
402407
})
403408
#define ROR64c(word,i) ({ \
404-
ulong64 ROR64c_tmp = word; \
409+
ulong64 LTC_TMPVAR(ROR64c) = word; \
405410
__asm__ ("rorq %2, %0" : \
406-
"=r" (ROR64c_tmp) : \
407-
"0" (ROR64c_tmp), \
411+
"=r" (LTC_TMPVAR(ROR64c)) : \
412+
"0" (LTC_TMPVAR(ROR64c)), \
408413
"J" (i)); \
409-
ROR64c_tmp; \
414+
LTC_TMPVAR(ROR64c); \
410415
})
411416

412417
#else /* LTC_NO_ROLC */

src/headers/tomcrypt_pk.h

+31-31
Original file line numberDiff line numberDiff line change
@@ -548,43 +548,43 @@ typedef struct ltc_asn1_list_ {
548548
struct ltc_asn1_list_ *prev, *next, *child, *parent;
549549
} ltc_asn1_list;
550550

551-
#define LTC_SET_ASN1(list, index, Type, Data, Size) \
552-
do { \
553-
int LTC_MACRO_temp = (index); \
554-
ltc_asn1_list *LTC_MACRO_list = (list); \
555-
LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
556-
LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \
557-
LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
558-
LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
559-
LTC_MACRO_list[LTC_MACRO_temp].optional = 0; \
560-
LTC_MACRO_list[LTC_MACRO_temp].klass = 0; \
561-
LTC_MACRO_list[LTC_MACRO_temp].pc = 0; \
562-
LTC_MACRO_list[LTC_MACRO_temp].tag = 0; \
551+
#define LTC_SET_ASN1(list, index, Type, Data, Size) \
552+
do { \
553+
int LTC_TMPVAR(SA) = (index); \
554+
ltc_asn1_list *LTC_TMPVAR(SA_list) = (list); \
555+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].type = (Type); \
556+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].data = (void*)(Data); \
557+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].size = (Size); \
558+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].used = 0; \
559+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].optional = 0; \
560+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].klass = 0; \
561+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].pc = 0; \
562+
LTC_TMPVAR(SA_list)[LTC_TMPVAR(SA)].tag = 0; \
563563
} while (0)
564564

565-
#define LTC_SET_ASN1_IDENTIFIER(list, index, Class, Pc, Tag) \
566-
do { \
567-
int LTC_MACRO_temp = (index); \
568-
ltc_asn1_list *LTC_MACRO_list = (list); \
569-
LTC_MACRO_list[LTC_MACRO_temp].type = LTC_ASN1_CUSTOM_TYPE; \
570-
LTC_MACRO_list[LTC_MACRO_temp].klass = (Class); \
571-
LTC_MACRO_list[LTC_MACRO_temp].pc = (Pc); \
572-
LTC_MACRO_list[LTC_MACRO_temp].tag = (Tag); \
565+
#define LTC_SET_ASN1_IDENTIFIER(list, index, Class, Pc, Tag) \
566+
do { \
567+
int LTC_TMPVAR(SAI) = (index); \
568+
ltc_asn1_list *LTC_TMPVAR(SAI_list) = (list); \
569+
LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].type = LTC_ASN1_CUSTOM_TYPE; \
570+
LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].klass = (Class); \
571+
LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].pc = (Pc); \
572+
LTC_TMPVAR(SAI_list)[LTC_TMPVAR(SAI)].tag = (Tag); \
573573
} while (0)
574574

575-
#define LTC_SET_ASN1_CUSTOM_CONSTRUCTED(list, index, Class, Tag, Data) \
576-
do { \
577-
int LTC_MACRO_temp##__LINE__ = (index); \
578-
LTC_SET_ASN1(list, LTC_MACRO_temp##__LINE__, LTC_ASN1_CUSTOM_TYPE, Data, 1); \
579-
LTC_SET_ASN1_IDENTIFIER(list, LTC_MACRO_temp##__LINE__, Class, LTC_ASN1_PC_CONSTRUCTED, Tag); \
575+
#define LTC_SET_ASN1_CUSTOM_CONSTRUCTED(list, index, Class, Tag, Data) \
576+
do { \
577+
int LTC_TMPVAR(SACC) = (index); \
578+
LTC_SET_ASN1(list, LTC_TMPVAR(SACC), LTC_ASN1_CUSTOM_TYPE, Data, 1); \
579+
LTC_SET_ASN1_IDENTIFIER(list, LTC_TMPVAR(SACC), Class, LTC_ASN1_PC_CONSTRUCTED, Tag); \
580580
} while (0)
581581

582-
#define LTC_SET_ASN1_CUSTOM_PRIMITIVE(list, index, Class, Tag, Type, Data, Size) \
583-
do { \
584-
int LTC_MACRO_temp##__LINE__ = (index); \
585-
LTC_SET_ASN1(list, LTC_MACRO_temp##__LINE__, LTC_ASN1_CUSTOM_TYPE, Data, Size); \
586-
LTC_SET_ASN1_IDENTIFIER(list, LTC_MACRO_temp##__LINE__, Class, LTC_ASN1_PC_PRIMITIVE, Tag); \
587-
list[LTC_MACRO_temp##__LINE__].used = (int)(Type); \
582+
#define LTC_SET_ASN1_CUSTOM_PRIMITIVE(list, index, Class, Tag, Type, Data, Size) \
583+
do { \
584+
int LTC_TMPVAR(SACP) = (index); \
585+
LTC_SET_ASN1(list, LTC_TMPVAR(SACP), LTC_ASN1_CUSTOM_TYPE, Data, Size); \
586+
LTC_SET_ASN1_IDENTIFIER(list, LTC_TMPVAR(SACP), Class, LTC_ASN1_PC_PRIMITIVE, Tag); \
587+
list[LTC_TMPVAR(SACP)].used = (int)(Type); \
588588
} while (0)
589589

590590
extern const char* der_asn1_class_to_string_map[];

0 commit comments

Comments
 (0)