1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-27 01:08:15 +00:00

fix CXXFLAGS="-Wall" warnings

This commit is contained in:
Mirek Kratochvil 2013-07-23 15:58:02 +02:00
parent 36b68d90c1
commit 66d7d84b13
14 changed files with 51 additions and 34 deletions

@ -4,6 +4,7 @@
COMMON_CPPFLAGS="-I/usr/local/include"
COMMON_CFLAGS="-Wall"
COMMON_CXXFLAGS="${COMMON_CFLAGS}"
COMMON_LDFLAGS="-L/usr/local/lib"
COMMON_LDADD=""
@ -23,6 +24,7 @@ echo "ccr_SOURCES = `( find src/ -type f -name \*.c ; find src/ -type f -name \*
echo "noinst_HEADERS = `find src/ -type f -name \*.h |tr \"\n\" \" \" `" >>$OUT
echo "ccr_CPPFLAGS = -I\$(srcdir)/$i/ ${COMMON_CPPFLAGS}" >>$OUT
echo "ccr_CFLAGS = ${COMMON_CFLAGS}" >>$OUT
echo "ccr_CXXFLAGS = ${COMMON_CXXFLAGS}" >>$OUT
echo "ccr_LDFLAGS = ${COMMON_LDFLAGS}" >>$OUT
echo "ccr_LDADD = -lgmp ${COMMON_LDADD} " >>$OUT

@ -96,6 +96,7 @@ int action_gen_key (const std::string& algspec, const std::string&name,
return 1;
}
//TODO this can fail, handle it.
KR.store_keypair (keyring::get_keyid (pub), name, algname, pub, priv);
//pub&priv data will get destroyed along with keyring
@ -1046,6 +1047,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp,
if (keyspec_matches (filter, i->second.name, i->first) ) {
KR.remove_pubkey (i->first);
KR.remove_keypair (i->first);
//TODO this can fail, handle it.
KR.store_pubkey (i->first,
name.length() ?
name : i->second.name,
@ -1297,6 +1299,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp,
if (keyspec_matches (filter, i->second.pub.name, i->first) ) {
KR.remove_pubkey (i->first);
KR.remove_keypair (i->first);
//TODO this can fail, handle it.
KR.store_keypair (i->first,
name.length() ?
name : i->second.pub.name,

@ -379,7 +379,8 @@ static int fo_decrypt (const bvector&cipher, bvector&plain,
ev.colex_rank (ev_rank);
ev_rank.resize (ranksize, 0);
for (i = 0; i < ranksize; ++i)
if (ev_rank[i] != 1 & (H[ (i >> 3) % H.size()] >> (i & 0x7) ) )
if (ev_rank[i] != (1 & (H[ (i >> 3) % H.size()]
>> (i & 0x7) ) ) )
return 8;

@ -30,12 +30,13 @@ template<class inttype> class arcfour
inttype mask;
public:
bool init (unsigned bits) {
size_t Ssize = 1 << bits;
if (bits > 8 * sizeof (inttype) ) return false;
I = J = 0;
S.resize (1 << bits);
S.resize (Ssize);
mask = ~ (inttype) 0;
if ( (inttype) (1 << bits) ) mask %= 1 << bits;
for (size_t i = 0; i < (1 << bits); ++i) S[i] = i;
for (size_t i = 0; i < Ssize; ++i) S[i] = i;
return true;
}

@ -21,7 +21,7 @@
void base64_encode (const std::string& in, std::string&out, int cols)
{
//note: it could be b64str[64], but we'd need -fpermissive
static const char b64str[65] =
static const unsigned char b64str[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned int acc = 0;
@ -50,7 +50,7 @@ void base64_encode (const std::string& in, std::string&out, int cols)
}
}
static void init_dec_str (char s[256])
static void init_dec_str (unsigned char s[256])
{
for (int i = 0; i < 256; ++i) s[i] = -1;
@ -126,12 +126,12 @@ static void init_dec_str (char s[256])
s['/'] = 63;
}
static inline bool is_white (char c)
static inline bool is_white (unsigned char c)
{
return (c == '\n') || (c == '\r') || (c == ' ') || (c == '\t');
}
static inline bool is_b64 (char c)
static inline bool is_b64 (unsigned char c)
{
return (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
@ -145,7 +145,7 @@ static void eat_white (const std::string&in, int&idx, int idxmax)
for (; (idx < idxmax) && is_white (in[idx]); ++idx);
}
static bool eat_4 (const std::string&in, int&idx, int idxmax, char*a)
static bool eat_4 (const std::string&in, int&idx, int idxmax, unsigned char*a)
{
for (int i = 0; i < 4; ++i) {
eat_white (in, idx, idxmax);
@ -159,7 +159,7 @@ static bool eat_4 (const std::string&in, int&idx, int idxmax, char*a)
bool base64_decode (const std::string& in, std::string&out)
{
static char b64d[256];
static unsigned char b64d[256];
static bool b64d_init = false;
if (!b64d_init) {
@ -173,7 +173,7 @@ bool base64_decode (const std::string& in, std::string&out)
out.reserve (3 * in.length() / 4);
//start parsing
char c[4];
unsigned char c[4];
while (eat_4 (in, idx, idxmax, c) ) {
for (int i = 0; i < 4; ++i)
c[i] = b64d[c[i]]; // '=' gets converted to -1

@ -265,7 +265,7 @@ void bvector::colex_rank (bvector&r) const
bool bvector::colex_unrank (bvector&res, uint n, uint k) const
{
mpz_t r, comb, t, t2;
mpz_t r, comb, t;
mpz_init (r);
mpz_init (comb);
mpz_init (t);

@ -64,10 +64,11 @@ static void store_exist (privkey&priv, const privkey::tree_stk_item&i)
{
uint level = i.level / priv.h;
if (level >= priv.l) return; //top node
uint sublevel = priv.h - (i.level % priv.h);
if (i.pos >= (1 << sublevel) ) return; //too far right
uint sublevel = priv.h - (i.level % priv.h),
sublev_width = (uint) 1 << sublevel;
if (i.pos >= sublev_width) return; //too far right
priv.exist[level][i.pos + (1 << sublevel) - 2] = i.item;
priv.exist[level][i.pos + sublev_width - 2] = i.item;
}
static void alloc_desired (privkey&priv, hash_func&hf)
@ -88,7 +89,7 @@ static void store_desired (privkey&priv, uint did,
{
if ( (i.level / priv.h) != did) return; //too below or above
uint depth = priv.h - (i.level % priv.h);
if (i.pos >= (1 << depth) ) return; //too far right, omg why?!
if (i.pos >= ( (uint) 1 << depth) ) return; //too far right, omg why?!
priv.desired[did][i.pos + (1 << depth) - 2] = i.item;
}
@ -206,7 +207,7 @@ static void update_privkey (privkey&priv, hash_func&hf)
uint next_subtree_start =
(1 + (next_sigs_used >> ( (1 + idx) * priv.h) ) )
<< ( (1 + idx) * priv.h);
if (next_subtree_start >= (1 << (priv.h * priv.l) ) ) {
if (next_subtree_start >= ( (uint) 1 << (priv.h * priv.l) ) ) {
priv.desired.resize (idx);
priv.desired_stack.resize (idx);
priv.desired_progress.resize (idx);

@ -299,12 +299,13 @@ static bool ensure_empty_sencode_file (const std::string&fn,
l.items.push_back (&b);
std::string emptyfile = l.encode();
int fd, res;
int fd;
fd = creat (fn.c_str(), S_IRUSR | S_IWUSR);
if (fd < 0) return false;
res = write (fd, emptyfile.c_str(), emptyfile.length() );
ssize_t res = write (fd, emptyfile.c_str(),
emptyfile.length() );
if (close (fd) ) return false;
if (res != emptyfile.length() ) return false;
if ( (size_t) res != emptyfile.length() ) return false;
} else {
if (!S_ISREG (st.st_mode) )

@ -115,6 +115,7 @@ public:
if (pairs.count (keyid) ) return false;
if (pubs.count (keyid) ) return false;
pubs[keyid] = pubkey_entry (keyid, name, alg, key);
return true;
}
void remove_pubkey (const std::string&keyid) {
@ -138,6 +139,7 @@ public:
if (pubs.count (keyid) ) return false;
pairs[keyid] = keypair_entry (keyid, name, alg,
pubkey, privkey);
return true;
}
void remove_keypair (const std::string&keyid) {

@ -64,7 +64,7 @@ int mce_qd::generate (pubkey&pub, privkey&priv, prng&rng,
essence[m - 1] = fld.inv (Hsig[0]);
//essence[m-1] is now used as precomputed 1/h_0
for (uint s = 0; (1 << s) < n; ++s) {
for (uint s = 0; ( (uint) 1 << s) < n; ++s) {
i = 1 << s; //i = 2^s
Hsig[i] = choose_random (fld.n, rng, used);
@ -220,7 +220,7 @@ int privkey::prepare()
//compute H signature from essence
Hsig.resize (n);
Hsig[0] = fld.inv (essence[fld.m - 1]);
for (s = 0; (1 << s) < n; ++s) {
for (s = 0; ( (uint) 1 << s) < n; ++s) {
i = 1 << s; //i = 2^s
Hsig[i] = fld.inv (fld.add (essence[s], essence[fld.m - 1]) );
@ -246,7 +246,7 @@ int privkey::prepare()
g.resize (1, 1); //g(x)=1
tmp.clear();
tmp.resize (2, 1); //tmp(x)=x+1
for (i = 0; i < (1 << T); ++i) {
for (i = 0; i < block_size; ++i) {
tmp[0] = fld.inv (Hsig[i]); //tmp(x)=x+1/h_i
if (used.count (tmp[0]) )
return 1;
@ -286,7 +286,7 @@ int privkey::prepare()
tmp.clear();
g.resize (1, 1); //g(x)=1
tmp.resize (2, 1); //tmp(x)=x+1
for (i = 0; i < (1 << T); ++i) {
for (i = 0; i < block_size; ++i) {
tmp[0] = fld.add (fld.inv (Hsig[i]), omega);
g.mult (tmp, fld);
}
@ -351,7 +351,7 @@ int pubkey::encrypt (const bvector & in, bvector & out, const bvector&errors)
{
uint t = 1 << T;
bvector p, g, r, cksum;
uint i, j, k;
uint i, j;
/*
* shortened checksum pair of G is computed blockwise accordingly to

@ -85,13 +85,12 @@ void polynomial::mod (const polynomial&f, gf2m&fld)
void polynomial::mult (const polynomial&b, gf2m&fld)
{
polynomial a = *this;
uint i, j;
int da, db;
int da, db, i, j;
da = a.degree();
db = b.degree();
clear();
if ( (da < 0) || (db < 0) ) //multiply by zero
if ( (da < 0) || (db < 0) ) //multiply by zero, not much to do.
return;
resize (da + db + 1, 0);
@ -261,7 +260,7 @@ void polynomial::make_monic (gf2m&fld)
int d = degree();
if (d < 0) return;
uint m = fld.inv (item (d) );
for (uint i = 0; i <= d; ++i) item (i) = fld.mult (item (i), m);
for (int i = 0; i <= d; ++i) item (i) = fld.mult (item (i), m);
}
void polynomial::shift (uint n)
@ -342,9 +341,9 @@ void polynomial::divmod (polynomial&d, polynomial&res, polynomial&rem, gf2m&fld)
int t;
while ( (t = rem.degree() ) >= degd) {
int rp = t - degd;
if (res.size() < rp + 1) res.resize (rp + 1, 0);
if ( (int) res.size() < rp + 1) res.resize (rp + 1, 0);
res[rp] = fld.mult (headInv, rem[t]);
for (uint i = 0; i <= degd; ++i)
for (int i = 0; i <= degd; ++i)
rem[i + rp] = fld.add (rem[i + rp], fld.mult (res[rp], d[i]) );
}
rem.strip();

@ -28,7 +28,7 @@
static void fwht (std::vector<int> x, std::vector<int>&r)
{
int bs, s;
uint bs, s;
s = x.size();
bs = s >> 1;
r.swap (x);

@ -21,6 +21,11 @@
#include <sstream>
#include <list>
/*
* TODO
* fix: set some maximum integer to avoid overflows and keep the top limit
*/
static void parse_int (const std::string&str, int&pos, int len,
unsigned int&res)
{
@ -62,7 +67,7 @@ static void parse_string (const std::string&str, int&pos, int len,
std::string&res)
{
//first, read the amount of bytes
unsigned int bytes = 0;
int bytes = 0;
/*
* we need to keep this bijective, therefore avoid parsing of any
@ -84,7 +89,7 @@ static void parse_string (const std::string&str, int&pos, int len,
if (pos >= len) goto fail;
else if (str[pos] == ':') break; //got it
else if ( (str[pos] >= '0') and (str[pos] <= '9') ) //integer
bytes = (10 * bytes) + (unsigned int) (str[pos] - '0');
bytes = (10 * bytes) + (int) (str[pos] - '0');
else goto fail; //weird!
++pos;
}
@ -95,7 +100,7 @@ bytes_done:
if (pos + bytes >= len) goto fail;
res = str.substr (pos, bytes);
pos += bytes;
--pos; //last char of the bytestring
--pos; //set position to last char of the bytestring (not behind it)
return;
fail:
pos = -1;

@ -33,6 +33,8 @@ class sencode
public:
virtual std::string encode() = 0;
virtual void destroy() {}
virtual ~sencode() {}
};
sencode* sencode_decode (const std::string&);