Companion checkin to 572506de3d. Salsa and Sosemanuk can no longer reach into a SecBlock for and touch its private members

pull/35/head
Jeffrey Walton 2015-08-03 19:06:18 -04:00
parent 572506de3d
commit 7e6c9438da
2 changed files with 18 additions and 10 deletions

View File

@ -8,6 +8,8 @@
#include "salsa.h" #include "salsa.h"
#include "misc.h" #include "misc.h"
#include "stdcpp.h"
#include "smartptr.h"
#include "argnames.h" #include "argnames.h"
#include "cpu.h" #include "cpu.h"
#include "trap.h" #include "trap.h"
@ -89,8 +91,11 @@ void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output
{ {
#endif // #ifdef CRYPTOPP_GENERATE_X64_MASM #endif // #ifdef CRYPTOPP_GENERATE_X64_MASM
// m_state.m_ptr was used below. Fetch it through data() member so we can make SecBlock's members private
word32* state = m_state.data();
#ifdef CRYPTOPP_X64_MASM_AVAILABLE #ifdef CRYPTOPP_X64_MASM_AVAILABLE
Salsa20_OperateKeystream(output, input, iterationCount, m_rounds, m_state.data()); Salsa20_OperateKeystream(output, input, iterationCount, m_rounds, state);
return; return;
#endif #endif
@ -154,14 +159,13 @@ void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output
GNU_AS_INTEL_SYNTAX GNU_AS_INTEL_SYNTAX
AS_PUSH_IF86( bx) AS_PUSH_IF86( bx)
#else #else
void *s = m_state.data(); word32 rounds = m_rounds;
word32 r = m_rounds;
AS2( mov REG_iterationCount, iterationCount) AS2( mov REG_iterationCount, iterationCount)
AS2( mov REG_input, input) AS2( mov REG_input, input)
AS2( mov REG_output, output) AS2( mov REG_output, output)
AS2( mov REG_state, s) AS2( mov REG_state, state)
AS2( mov REG_rounds, r) AS2( mov REG_rounds, rounds)
#endif #endif
#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM
@ -462,11 +466,11 @@ void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output
GNU_AS_ATT_SYNTAX GNU_AS_ATT_SYNTAX
#if CRYPTOPP_BOOL_X64 #if CRYPTOPP_BOOL_X64
: "+r" (input), "+r" (output), "+r" (iterationCount) : "+r" (input), "+r" (output), "+r" (iterationCount)
: "r" (m_rounds), "r" (m_state.m_ptr), "r" (workspace) : "r" (m_rounds), "r" (state), "r" (workspace)
: "%eax", "%rdx", "memory", "cc", "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", "%xmm8", "%xmm9", "%xmm10", "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15" : "%eax", "%rdx", "memory", "cc", "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", "%xmm8", "%xmm9", "%xmm10", "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15"
#else #else
: "+a" (input), "+D" (output), "+c" (iterationCount) : "+a" (input), "+D" (output), "+c" (iterationCount)
: "d" (m_rounds), "S" (m_state.m_ptr) : "d" (m_rounds), "S" (state)
: "memory", "cc" : "memory", "cc"
#endif #endif
); );

View File

@ -326,8 +326,11 @@ void SosemanukPolicy::OperateKeystream(KeystreamOperation operation, byte *outpu
{ {
#endif // #ifdef CRYPTOPP_GENERATE_X64_MASM #endif // #ifdef CRYPTOPP_GENERATE_X64_MASM
// m_state.m_ptr was used below. Fetch it through data() member so we can make SecBlock's members private
word32* state = m_state.data();
#ifdef CRYPTOPP_X64_MASM_AVAILABLE #ifdef CRYPTOPP_X64_MASM_AVAILABLE
Sosemanuk_OperateKeystream(iterationCount, input, output, m_state.data()); Sosemanuk_OperateKeystream(iterationCount, input, output, state);
return; return;
#endif #endif
@ -353,6 +356,7 @@ void SosemanukPolicy::OperateKeystream(KeystreamOperation operation, byte *outpu
#ifdef __GNUC__ #ifdef __GNUC__
#if CRYPTOPP_BOOL_X64 #if CRYPTOPP_BOOL_X64
FixedSizeAlignedSecBlock<byte, 80*4*2+12*4+8*WORD_SZ> workspace; FixedSizeAlignedSecBlock<byte, 80*4*2+12*4+8*WORD_SZ> workspace;
const byte* space = workspace.data();
#endif #endif
__asm__ __volatile__ __asm__ __volatile__
( (
@ -598,9 +602,9 @@ void SosemanukPolicy::OperateKeystream(KeystreamOperation operation, byte *outpu
AS_POP_IF86( bx) AS_POP_IF86( bx)
GNU_AS_ATT_SYNTAX GNU_AS_ATT_SYNTAX
: :
: "a" (m_state.m_ptr), "c" (iterationCount), "S" (s_sosemanukMulTables), "D" (output), "d" (input) : "a" (state), "c" (iterationCount), "S" (s_sosemanukMulTables), "D" (output), "d" (input)
#if CRYPTOPP_BOOL_X64 #if CRYPTOPP_BOOL_X64
, "r" (workspace.m_ptr) , "r" (space)
: "memory", "cc", "%r9", "%r10", "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" : "memory", "cc", "%r9", "%r10", "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7"
#else #else
: "memory", "cc" : "memory", "cc"