Skip to content

Commit 62878de

Browse files
compnerdsjaeckel
authored andcommitted
adjust inline asm requiring constants
In order to ensure that the shift is within range, convert the inline assembly routines into macros with compound statements.
1 parent e9f9c6f commit 62878de

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/headers/tomcrypt_macros.h

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,22 @@ static inline ulong32 ROR(ulong32 word, int i)
264264

265265
#ifndef LTC_NO_ROLC
266266

267-
static inline ulong32 ROLc(ulong32 word, const int i)
268-
{
269-
asm ("roll %2,%0"
270-
:"=r" (word)
271-
:"0" (word),"I" (i));
272-
return word;
273-
}
274-
275-
static inline ulong32 RORc(ulong32 word, const int i)
276-
{
277-
asm ("rorl %2,%0"
278-
:"=r" (word)
279-
:"0" (word),"I" (i));
280-
return word;
281-
}
267+
#define ROLc(word,i) ({ \
268+
ulong32 __ROLc_tmp = word; \
269+
__asm__ ("roll %2, %0" : \
270+
"=r" (__ROLc_tmp) : \
271+
"0" (__ROLc_tmp), \
272+
"I" (i)); \
273+
__ROLc_tmp; \
274+
})
275+
#define RORc(word,i) ({ \
276+
ulong32 __RORc_tmp = word; \
277+
__asm__ ("rorl %2, %0" : \
278+
"=r" (__RORc_tmp) : \
279+
"0" (__RORc_tmp), \
280+
"I" (i)); \
281+
__RORc_tmp; \
282+
})
282283

283284
#else
284285

@@ -363,21 +364,22 @@ static inline ulong64 ROR64(ulong64 word, int i)
363364

364365
#ifndef LTC_NO_ROLC
365366

366-
static inline ulong64 ROL64c(ulong64 word, const int i)
367-
{
368-
asm("rolq %2,%0"
369-
:"=r" (word)
370-
:"0" (word),"J" (i));
371-
return word;
372-
}
373-
374-
static inline ulong64 ROR64c(ulong64 word, const int i)
375-
{
376-
asm("rorq %2,%0"
377-
:"=r" (word)
378-
:"0" (word),"J" (i));
379-
return word;
380-
}
367+
#define ROL64c(word,i) ({ \
368+
ulong64 __ROL64c_tmp = word; \
369+
__asm__ ("rolq %2, %0" : \
370+
"=r" (__ROL64c_tmp) : \
371+
"0" (__ROL64c_tmp), \
372+
"J" (i)); \
373+
__ROL64c_tmp; \
374+
})
375+
#define ROR64c(word,i) ({ \
376+
ulong64 __ROR64c_tmp = word; \
377+
__asm__ ("rorq %2, %0" : \
378+
"=r" (__ROR64c_tmp) : \
379+
"0" (__ROR64c_tmp), \
380+
"J" (i)); \
381+
__ROR64c_tmp; \
382+
})
381383

382384
#else /* LTC_NO_ROLC */
383385

0 commit comments

Comments
 (0)