Skip to content

Commit

Permalink
Merge pull request #171 from VirgilSecurity/fix/pythia-backward-compa…
Browse files Browse the repository at this point in the history
…tibility

Revert back to relic 0.4.0 to restore Pythia backward compatibility

Fixed relic version is 0.4.1
  • Loading branch information
SergeySeroshtan committed Aug 13, 2023
2 parents 3a7cfe4 + 21fbed0 commit 920707b
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 247 deletions.
1 change: 1 addition & 0 deletions library/pythia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ target_sources(pythia
${CMAKE_CURRENT_LIST_DIR}/src/pythia_buf_exports.h
${CMAKE_CURRENT_LIST_DIR}/src/pythia_buf_sizes_c.h
${CMAKE_CURRENT_LIST_DIR}/src/pythia_c.h
${CMAKE_CURRENT_LIST_DIR}/src/pythia_init_c.h

${CMAKE_CURRENT_LIST_DIR}/src/pythia_buf.c
${CMAKE_CURRENT_LIST_DIR}/src/pythia_buf_exports.c
Expand Down
15 changes: 7 additions & 8 deletions library/pythia/src/pythia_buf_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@

#include <relic/relic.h>
#include <relic/relic_err.h>
#include <relic/relic_label.h>
#include <pythia.h>
#include "pythia_buf.h"
#include "pythia_buf_exports.h"

static void
check_size_read(const pythia_buf_t *buf, size_t min_size, size_t max_size) {
if (!buf || buf->len < min_size || buf->len > max_size)
RLC_THROW(ERR_NO_BUFFER);
THROW(ERR_NO_BUFFER);
}

static void
check_size_write(const pythia_buf_t *buf, size_t min_size) {
if (!buf || buf->allocated < min_size)
RLC_THROW(ERR_NO_BUFFER);
THROW(ERR_NO_BUFFER);
}

void
Expand All @@ -40,8 +39,8 @@ bn_read_buf(bn_t b, const pythia_buf_t *buf) {

uint8_t sign = buf->p[0];

if (sign != RLC_POS && sign != RLC_NEG)
RLC_THROW(ERR_NO_VALID);
if (sign != BN_POS && sign != BN_NEG)
THROW(ERR_NO_VALID);

bn_read_bin(b, buf->p + 1, (int)(buf->len - 1));
b->sign = sign;
Expand All @@ -57,7 +56,7 @@ gt_read_buf(gt_t g, const pythia_buf_t *buf) {
zeroBytes += buf->p[i] == 0;
}
if (zeroBytes > 24)
RLC_THROW(ERR_NO_VALID);
THROW(ERR_NO_VALID);

gt_read_bin(g, buf->p, (int)buf->len);
}
Expand All @@ -67,15 +66,15 @@ g1_read_buf(g1_t g, const pythia_buf_t *buf) {
check_size_read(buf, 1, PYTHIA_G1_BUF_SIZE);
g1_read_bin(g, buf->p, (int)buf->len);
if (!g1_is_valid(g))
RLC_THROW(ERR_NO_VALID);
THROW(ERR_NO_VALID);
}

void
g2_read_buf(g2_t g, const pythia_buf_t *buf) {
check_size_read(buf, 1, PYTHIA_G2_BUF_SIZE);
g2_read_bin(g, buf->p, (int)buf->len);
if (!g2_is_valid(g))
RLC_THROW(ERR_NO_VALID);
THROW(ERR_NO_VALID);
}

void
Expand Down
6 changes: 3 additions & 3 deletions library/pythia/src/pythia_buf_sizes_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

#include <relic/relic.h>

#define DEF_PYTHIA_G1_BUF_SIZE RLC_FP_BYTES + 1
#define DEF_PYTHIA_G1_BUF_SIZE FP_BYTES + 1

#define DEF_PYTHIA_G2_BUF_SIZE 2 * RLC_FP_BYTES + 1
#define DEF_PYTHIA_G2_BUF_SIZE 2 * FP_BYTES + 1

#define DEF_PYTHIA_GT_BUF_SIZE 8 * RLC_FP_BYTES
#define DEF_PYTHIA_GT_BUF_SIZE 8 * FP_BYTES

#define DEF_PYTHIA_BN_BUF_SIZE DEF_PYTHIA_G1_BUF_SIZE + 1

Expand Down
Loading

0 comments on commit 920707b

Please sign in to comment.