Skip to content

Commit

Permalink
Process MemSan alarms
Browse files Browse the repository at this point in the history
  • Loading branch information
agievich committed Mar 7, 2023
1 parent 739ef70 commit 310b342
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
19 changes: 10 additions & 9 deletions src/core/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\brief Entropy sources and random number generators
\project bee2 [cryptographic library]
\created 2014.10.13
\version 2023.03.03
\version 2023.03.07
\copyright The Bee2 authors
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
*******************************************************************************
Expand Down Expand Up @@ -137,7 +137,7 @@ bool_t rngTestFIPS4(const octet buf[2500])
*******************************************************************************
*/

#if (_MSC_VER >= 1600) && (defined(_M_IX86) || defined(_M_X64))
#if (_MSC_VER >= 1600) && (defined(_M_IX86) || defined(_M_X64))

#include <intrin.h>
#include <immintrin.h>
Expand Down Expand Up @@ -197,7 +197,8 @@ static int rngRDStep2(u32* val)
return 0;
}

#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#elif (defined(__GNUC__) || defined(__clang__)) && \
(defined(__i386__) || defined(__x86_64__))

#include <cpuid.h>

Expand All @@ -206,15 +207,15 @@ static int rngRDStep2(u32* val)

static int rngRDStep(u32* val)
{
octet ok;
asm volatile("rdseed %0; setc %1" : "=r" (*val), "=qm" (ok));
octet ok = 0;
asm ("rdseed %0; setc %1" : "=r" (*val), "=qm" (ok));
return ok;
}

static int rngRDStep2(u32* val)
{
octet ok;
asm volatile("rdrand %0; setc %1" : "=r" (*val), "=qm" (ok));
octet ok = 0;
asm ("rdrand %0; setc %1" : "=r" (*val), "=qm" (ok));
return ok;
}

Expand Down Expand Up @@ -261,10 +262,10 @@ static err_t rngTRNGRead(void* buf, size_t* read, size_t count)
ASSERT(memIsValid(read, O_PER_S));
ASSERT(memIsValid(buf, count));
// есть источник?
*read = 0;
if (!rngTRNGIsAvail())
return ERR_FILE_NOT_FOUND;
// короткий буфер?
*read = 0;
if (count < 4)
return ERR_OK;
// генерация
Expand All @@ -289,10 +290,10 @@ static err_t rngTRNG2Read(void* buf, size_t* read, size_t count)
ASSERT(memIsValid(read, O_PER_S));
ASSERT(memIsValid(buf, count));
// есть источник?
*read = 0;
if (!rngTRNG2IsAvail())
return ERR_FILE_NOT_FOUND;
// короткий буфер?
*read = 0;
if (count < 4)
return ERR_OK;
// генерация
Expand Down
4 changes: 2 additions & 2 deletions src/math/zz/zz_gcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\brief Multiple-precision unsigned integers: Euclidian gcd algorithms
\project bee2 [cryptographic library]
\created 2012.04.22
\version 2023.02.10
\version 2023.03.07
\copyright The Bee2 authors
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
*******************************************************************************
Expand Down Expand Up @@ -287,7 +287,7 @@ void zzExGCD(word d[], word da[], word db[], const word a[], size_t n,
// d <- u
wwCopy(d, u, nu);
// d <- d * 2^s
wwShHi(d, W_OF_B(wwBitSize(d, m) + s), s);
wwShHi(d, W_OF_B(wwBitSize(d, nu) + s), s);
// очистка
s = nu = mv = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion test/core/apdu_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\brief Tests for APDU formats
\project bee2/test
\created 2022.10.31
\version 2022.11.03
\version 2023.03.07
\copyright The Bee2 authors
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
*******************************************************************************
Expand Down Expand Up @@ -52,6 +52,7 @@ bool_t apduTest()
return FALSE;
// cmd: сочетания длин
cmd->cla = 0x00, cmd->ins = 0xA4, cmd->p1 = 0x04, cmd->p2 = 0x04;
memSet(cmd->cdf, 0x36, 257);
for (cmd->cdf_len = 0; cmd->cdf_len <= 257; ++cmd->cdf_len)
for (cmd->rdf_len = 0; cmd->rdf_len <= 257; ++cmd->rdf_len)
{
Expand Down
4 changes: 3 additions & 1 deletion test/crypto/btok_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\brief Tests for STB 34.101.79 (btok)
\project bee2/test
\created 2022.07.07
\version 2022.12.12
\version 2023.03.07
\copyright The Bee2 authors
\license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
*******************************************************************************
Expand Down Expand Up @@ -328,6 +328,8 @@ static bool_t btokSMTest()
return FALSE;
// защита команд и ответов: сочетания длин
cmd->cla = 0x00, cmd->ins = 0xA4, cmd->p1 = 0x04, cmd->p2 = 0x04;
memSet(cmd->cdf, 0x36, 257);
memSet(resp->rdf, 0x5C, 257);
for (cmd->cdf_len = 0; cmd->cdf_len <= 257; ++cmd->cdf_len)
for (cmd->rdf_len = 0; cmd->rdf_len <= 257; ++cmd->rdf_len)
{
Expand Down

0 comments on commit 310b342

Please sign in to comment.