Skip to content

Commit

Permalink
Use memzero() from bc-crypto-base instead of memset().
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmcnally committed Aug 16, 2021
1 parent 718a3ab commit c40b37f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ config.h
# wasm
*.wasm*
sskr.js

.vscode/*.log
3 changes: 1 addition & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([bc-sskr], [0.2.0])
AC_INIT([bc-sskr], [0.3.0])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])

Expand Down Expand Up @@ -32,7 +32,6 @@ AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset])

AC_CONFIG_FILES([Makefile
src/Makefile
Expand Down
24 changes: 13 additions & 11 deletions src/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "sskr-errors.h"

#if defined(ARDUINO) || defined(__EMSCRIPTEN__)
#include "bc-crypto-base.h"
#include "bc-shamir.h"
#else
#include <bc-crypto-base/bc-crypto-base.h>
#include <bc-shamir/bc-shamir.h>
#endif

Expand Down Expand Up @@ -195,18 +197,18 @@ static int generate_shards(
shard->group_index = i;
shard->member_threshold = groups[i].threshold;
shard->member_index = j;
memset(shard->value, 0, 32);
memzero(shard->value, 32);
memcpy(shard->value, value, master_secret_len);

shards_count++;
}

// clean up
memset(member_shares, 0, sizeof(member_shares));
memzero(member_shares, sizeof(member_shares));
}

// clean up stack
memset(group_shares, 0, sizeof(group_shares));
memzero(group_shares, sizeof(group_shares));

// return the number of shards generated
return shards_count;
Expand Down Expand Up @@ -272,9 +274,9 @@ int sskr_generate(
cur_output += byte_count;
}

memset(shards, 0, sizeof(shards));
memzero(shards, sizeof(shards));
if(error) {
memset(output, 0, buffer_size);
memzero(output, buffer_size);
return 0;
}

Expand Down Expand Up @@ -417,10 +419,10 @@ static int combine_shards_internal(
}

// clean up stack
memset(group_shares, 0, sizeof(group_shares));
memset(gx, 0, sizeof(gx));
memset(gy, 0, sizeof(gy));
memset(groups, 0, sizeof(groups));
memzero(group_shares, sizeof(group_shares));
memzero(gx, sizeof(gx));
memzero(gy, sizeof(gy));
memzero(groups, sizeof(groups));

if(error) {
return error;
Expand All @@ -444,7 +446,7 @@ static int combine_shards(

int result = combine_shards_internal(working_shards, shards_count, buffer, buffer_len);

memset(working_shards,0, sizeof(working_shards));
memzero(working_shards, sizeof(working_shards));

return result;
}
Expand Down Expand Up @@ -481,7 +483,7 @@ int sskr_combine(
result = combine_shards_internal(shards, shards_count, buffer, buffer_len);
}

memset(shards,0,sizeof(shards));
memzero(shards, sizeof(shards));

return result;
}

0 comments on commit c40b37f

Please sign in to comment.