diff --git a/autogen.sh b/autogen.sh index ac48e47..1129f5e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -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 diff --git a/src/actions.cpp b/src/actions.cpp index 7c6a56e..38202ed 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -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, diff --git a/src/algos_enc.cpp b/src/algos_enc.cpp index 8042a80..bbaa85d 100644 --- a/src/algos_enc.cpp +++ b/src/algos_enc.cpp @@ -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; diff --git a/src/arcfour.h b/src/arcfour.h index fd019cb..a7e7fa3 100644 --- a/src/arcfour.h +++ b/src/arcfour.h @@ -30,12 +30,13 @@ template 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; } diff --git a/src/base64.cpp b/src/base64.cpp index 108da08..b422630 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -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 diff --git a/src/bvector.cpp b/src/bvector.cpp index 6735587..5991df6 100644 --- a/src/bvector.cpp +++ b/src/bvector.cpp @@ -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); diff --git a/src/fmtseq.cpp b/src/fmtseq.cpp index a54d143..7facc3c 100644 --- a/src/fmtseq.cpp +++ b/src/fmtseq.cpp @@ -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); diff --git a/src/keyring.cpp b/src/keyring.cpp index 5e320c5..3e7afe0 100644 --- a/src/keyring.cpp +++ b/src/keyring.cpp @@ -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) ) diff --git a/src/keyring.h b/src/keyring.h index dc6968e..fc18d9f 100644 --- a/src/keyring.h +++ b/src/keyring.h @@ -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) { diff --git a/src/mce_qd.cpp b/src/mce_qd.cpp index ab2e286..492b279 100644 --- a/src/mce_qd.cpp +++ b/src/mce_qd.cpp @@ -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 diff --git a/src/polynomial.cpp b/src/polynomial.cpp index dfb5063..12df833 100644 --- a/src/polynomial.cpp +++ b/src/polynomial.cpp @@ -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(); diff --git a/src/qd_utils.cpp b/src/qd_utils.cpp index 43df826..7fdb4b4 100644 --- a/src/qd_utils.cpp +++ b/src/qd_utils.cpp @@ -28,7 +28,7 @@ static void fwht (std::vector x, std::vector&r) { - int bs, s; + uint bs, s; s = x.size(); bs = s >> 1; r.swap (x); diff --git a/src/sencode.cpp b/src/sencode.cpp index e95f0b3..98c3f73 100644 --- a/src/sencode.cpp +++ b/src/sencode.cpp @@ -21,6 +21,11 @@ #include #include +/* + * 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; diff --git a/src/sencode.h b/src/sencode.h index b16c70f..2d46eb2 100644 --- a/src/sencode.h +++ b/src/sencode.h @@ -33,6 +33,8 @@ class sencode public: virtual std::string encode() = 0; virtual void destroy() {} + + virtual ~sencode() {} }; sencode* sencode_decode (const std::string&);