Skip to content

Commit

Permalink
adjust inline asm requiring constants
Browse files Browse the repository at this point in the history
In order to ensure that the shift is within range, convert the inline assembly
routines into macros with compound statements.
  • Loading branch information
compnerd authored and sjaeckel committed Jan 20, 2015
1 parent e9f9c6f commit 62878de
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/headers/tomcrypt_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,22 @@ static inline ulong32 ROR(ulong32 word, int i)

#ifndef LTC_NO_ROLC

static inline ulong32 ROLc(ulong32 word, const int i)
{
asm ("roll %2,%0"
:"=r" (word)
:"0" (word),"I" (i));
return word;
}

static inline ulong32 RORc(ulong32 word, const int i)
{
asm ("rorl %2,%0"
:"=r" (word)
:"0" (word),"I" (i));
return word;
}
#define ROLc(word,i) ({ \
ulong32 __ROLc_tmp = word; \
__asm__ ("roll %2, %0" : \
"=r" (__ROLc_tmp) : \
"0" (__ROLc_tmp), \
"I" (i)); \
__ROLc_tmp; \
})
#define RORc(word,i) ({ \
ulong32 __RORc_tmp = word; \
__asm__ ("rorl %2, %0" : \
"=r" (__RORc_tmp) : \
"0" (__RORc_tmp), \
"I" (i)); \
__RORc_tmp; \
})

#else

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

#ifndef LTC_NO_ROLC

static inline ulong64 ROL64c(ulong64 word, const int i)
{
asm("rolq %2,%0"
:"=r" (word)
:"0" (word),"J" (i));
return word;
}

static inline ulong64 ROR64c(ulong64 word, const int i)
{
asm("rorq %2,%0"
:"=r" (word)
:"0" (word),"J" (i));
return word;
}
#define ROL64c(word,i) ({ \
ulong64 __ROL64c_tmp = word; \
__asm__ ("rolq %2, %0" : \
"=r" (__ROL64c_tmp) : \
"0" (__ROL64c_tmp), \
"J" (i)); \
__ROL64c_tmp; \
})
#define ROR64c(word,i) ({ \
ulong64 __ROR64c_tmp = word; \
__asm__ ("rorq %2, %0" : \
"=r" (__ROR64c_tmp) : \
"0" (__ROR64c_tmp), \
"J" (i)); \
__ROR64c_tmp; \
})

#else /* LTC_NO_ROLC */

Expand Down

0 comments on commit 62878de

Please sign in to comment.