From 19d59f9ec110221e5c78de0d0dce4a042c7f8b4d Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sat, 31 Oct 2015 22:58:17 +0100 Subject: [PATCH] bulk-apply new code styling rules --- src/actions.cpp | 286 +++++++++++++++++++++--------------------- src/algos_enc.cpp | 66 +++++----- src/algos_sig.cpp | 20 +-- src/arcfour.h | 6 +- src/base64.cpp | 14 +-- src/bvector.cpp | 36 +++--- src/cube_hash.h | 10 +- src/cubehash_impl.h | 18 +-- src/decoding.cpp | 18 +-- src/envelope.cpp | 16 +-- src/fmtseq.cpp | 102 +++++++-------- src/fmtseq.h | 6 +- src/gf2m.cpp | 6 +- src/gf2m.h | 6 +- src/hash.cpp | 2 +- src/hash.h | 2 +- src/hashfile.cpp | 16 +-- src/iohelpers.cpp | 8 +- src/iohelpers.h | 4 +- src/keyring.cpp | 56 ++++----- src/keyring.h | 20 +-- src/main.cpp | 8 +- src/matrix.cpp | 6 +- src/matrix.h | 2 +- src/mce.cpp | 22 ++-- src/message.cpp | 18 +-- src/nd.cpp | 14 +-- src/permutation.cpp | 2 +- src/permutation.h | 10 +- src/polynomial.cpp | 46 +++---- src/polynomial.h | 2 +- src/qd_utils.cpp | 6 +- src/sc.cpp | 2 +- src/sc.h | 2 +- src/sencode.cpp | 12 +- src/sencode.h | 2 +- src/serialization.cpp | 116 ++++++++--------- src/sha_hash.h | 8 +- src/str_match.cpp | 8 +- src/symkey.cpp | 58 ++++----- src/xsynd.cpp | 2 +- 41 files changed, 532 insertions(+), 532 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 721fdc8..841c14d 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -46,7 +46,7 @@ inline bool open_keyring (keyring&KR) { - if (!KR.open() ) { + if (!KR.open()) { err ("could not open keyring!"); return false; } @@ -62,7 +62,7 @@ int action_gen_symkey (const std::string&algspec, ccr_rng r; r.seed (256); - if (!sk.create (algspec, r) ) { + if (!sk.create (algspec, r)) { err ("error: symkey creation failed"); return 1; } @@ -87,13 +87,13 @@ int action_gen_symkey (const std::string&algspec, } sk_out << data; - if (!sk_out.good() ) { + if (!sk_out.good()) { err ("error: can't write to symkey file"); return 1; } sk_out.close(); - if (!sk_out.good() ) { + if (!sk_out.good()) { err ("error: couldn't close symkey file"); return 1; } @@ -165,20 +165,20 @@ int action_gen_key (const std::string& p_algspec, const std::string&name, //replace algorithm name on match with alias std::string algspec; - if (algspectable().count (p_algspec) ) + if (algspectable().count (p_algspec)) algspec = algspectable() [p_algspec]; else algspec = p_algspec; //handle symmetric operation - if (symmetric.length() ) + if (symmetric.length()) return action_gen_symkey (algspec, symmetric, armor); algorithm*alg = NULL; std::string algname; for (algorithm_suite::iterator i = AS.begin(), e = AS.end(); i != e; ++i) { - if (algorithm_name_matches (algspec, i->first) ) { + if (algorithm_name_matches (algspec, i->first)) { if (!alg) { algname = i->first; alg = i->second; @@ -195,7 +195,7 @@ int action_gen_key (const std::string& p_algspec, const std::string&name, return 1; } - if (!name.length() ) { + if (!name.length()) { err ("error: no key name provided"); return 1; } @@ -211,7 +211,7 @@ int action_gen_key (const std::string& p_algspec, const std::string&name, err ("Seeding done, generating the key..."); - if (alg->create_keypair (&pub, &priv, r) ) { + if (alg->create_keypair (&pub, &priv, r)) { err ("error: key generator failed"); return 1; } @@ -224,7 +224,7 @@ int action_gen_key (const std::string& p_algspec, const std::string&name, * improbable, so apologize nicely in that case. */ if (!KR.store_keypair (keyring::get_keyid (pub), - name, algname, pub, priv) ) { + name, algname, pub, priv)) { err ("error: new key cannot be saved into the keyring."); err ("notice: produced KeyID @" << keyring::get_keyid (pub) @@ -235,7 +235,7 @@ int action_gen_key (const std::string& p_algspec, const std::string&name, } //note that pub&priv sencode data will get destroyed along with keyring - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -260,7 +260,7 @@ int action_sym_encrypt (const std::string&symmetric, bool armor) } std::string sk_data; - if (!read_all_input (sk_data, sk_in) ) { + if (!read_all_input (sk_data, sk_in)) { err ("error: can't read symkey"); return 1; } @@ -269,7 +269,7 @@ int action_sym_encrypt (const std::string&symmetric, bool armor) if (armor) { std::vector parts; std::string type; - if (!envelope_read (sk_data, 0, type, parts) ) { + if (!envelope_read (sk_data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -279,7 +279,7 @@ int action_sym_encrypt (const std::string&symmetric, bool armor) return 1; } - if (!base64_decode (parts[0], sk_data) ) { + if (!base64_decode (parts[0], sk_data)) { err ("error: malformed data"); return 1; } @@ -292,7 +292,7 @@ int action_sym_encrypt (const std::string&symmetric, bool armor) } symkey sk; - if (!sk.unserialize (SK) ) { + if (!sk.unserialize (SK)) { err ("error: could not parse input structure"); return 1; } @@ -302,7 +302,7 @@ int action_sym_encrypt (const std::string&symmetric, bool armor) ccr_rng r; r.seed (256); - if (!sk.encrypt (std::cin, std::cout, r) ) { + if (!sk.encrypt (std::cin, std::cout, r)) { err ("error: encryption failed"); return 1; } @@ -314,7 +314,7 @@ int action_encrypt (const std::string&recipient, bool armor, const std::string&symmetric, keyring&KR, algorithm_suite&AS) { - if (symmetric.length() ) + if (symmetric.length()) return action_sym_encrypt (symmetric, armor); //first, read plaintext @@ -329,9 +329,9 @@ int action_encrypt (const std::string&recipient, bool armor, //search both publickeys and keypairs that are valid for encryption for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (recipient, i->second.name, i->first) ) { - if (!AS.count (i->second.alg) ) continue; - if (!AS[i->second.alg]->provides_encryption() ) + if (keyspec_matches (recipient, i->second.name, i->first)) { + if (!AS.count (i->second.alg)) continue; + if (!AS[i->second.alg]->provides_encryption()) continue; if (recip) { @@ -343,9 +343,9 @@ int action_encrypt (const std::string&recipient, bool armor, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (recipient, i->second.pub.name, i->first) ) { - if (!AS.count (i->second.pub.alg) ) continue; - if (!AS[i->second.pub.alg]->provides_encryption() ) + if (keyspec_matches (recipient, i->second.pub.name, i->first)) { + if (!AS.count (i->second.pub.alg)) continue; + if (!AS[i->second.pub.alg]->provides_encryption()) continue; if (recip) { @@ -368,7 +368,7 @@ int action_encrypt (const std::string&recipient, bool armor, bvector plaintext; plaintext.from_string (data); - if (msg.encrypt (plaintext, recip->alg, recip->keyid, AS, KR, r) ) { + if (msg.encrypt (plaintext, recip->alg, recip->keyid, AS, KR, r)) { err ("error: encryption failed"); return 1; } @@ -401,7 +401,7 @@ int action_sym_decrypt (const std::string&symmetric, bool armor) } std::string sk_data; - if (!read_all_input (sk_data, sk_in) ) { + if (!read_all_input (sk_data, sk_in)) { err ("error: can't read symkey"); return 1; } @@ -410,7 +410,7 @@ int action_sym_decrypt (const std::string&symmetric, bool armor) if (armor) { std::vector parts; std::string type; - if (!envelope_read (sk_data, 0, type, parts) ) { + if (!envelope_read (sk_data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -420,7 +420,7 @@ int action_sym_decrypt (const std::string&symmetric, bool armor) return 1; } - if (!base64_decode (parts[0], sk_data) ) { + if (!base64_decode (parts[0], sk_data)) { err ("error: malformed data"); return 1; } @@ -433,7 +433,7 @@ int action_sym_decrypt (const std::string&symmetric, bool armor) } symkey sk; - if (!sk.unserialize (SK) ) { + if (!sk.unserialize (SK)) { err ("error: could not parse input structure"); return 1; } @@ -449,7 +449,7 @@ int action_sym_decrypt (const std::string&symmetric, bool armor) int action_decrypt (bool armor, const std::string&symmetric, keyring&KR, algorithm_suite&AS) { - if (symmetric.length() ) + if (symmetric.length()) return action_sym_decrypt (symmetric, armor); std::string data; @@ -458,7 +458,7 @@ int action_decrypt (bool armor, const std::string&symmetric, if (armor) { std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -467,7 +467,7 @@ int action_decrypt (bool armor, const std::string&symmetric, err ("error: wrong envelope format"); return 1; } - if (!base64_decode (parts[0], data) ) { + if (!base64_decode (parts[0], data)) { err ("error: malformed data"); return 1; } @@ -476,14 +476,14 @@ int action_decrypt (bool armor, const std::string&symmetric, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); - if (!armor && envelope_lookalike (data) ) + if (!armor && envelope_lookalike (data)) err ("notice: input looks ascii-armored, " "try using the armor option"); return 1; } encrypted_msg msg; - if (!msg.unserialize (M) ) { + if (!msg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -503,8 +503,8 @@ int action_decrypt (bool armor, const std::string&symmetric, } //and the algorithm - if ( (!AS.count (msg.alg_id) ) - || (!AS[msg.alg_id]->provides_encryption() ) ) { + if ( (!AS.count (msg.alg_id)) + || (!AS[msg.alg_id]->provides_encryption())) { err ("error: decryption algorithm unsupported"); err ("info: requires algorithm " << msg.alg_id << " with encryption support"); @@ -514,12 +514,12 @@ int action_decrypt (bool armor, const std::string&symmetric, //actual decryption bvector plaintext; - if (msg.decrypt (plaintext, AS, KR) ) { + if (msg.decrypt (plaintext, AS, KR)) { err ("error: decryption failed"); return 1; } - if (!plaintext.to_string (data) ) { + if (!plaintext.to_string (data)) { err ("error: malformed data"); return 1; } @@ -538,7 +538,7 @@ int action_decrypt (bool armor, const std::string&symmetric, M = sencode_decode (data); if (M) { signed_msg m; - if (m.unserialize (M) ) { + if (m.unserialize (M)) { err ("notice: message content looks signed"); err ("hint: try also decrypt+verify operation"); } @@ -554,7 +554,7 @@ int action_decrypt (bool armor, const std::string&symmetric, int action_hash_sign (bool armor, const std::string&symmetric) { hashfile hf; - if (!hf.create (std::cin) ) { + if (!hf.create (std::cin)) { err ("error: hashing failed"); return 1; } @@ -581,13 +581,13 @@ int action_hash_sign (bool armor, const std::string&symmetric) } hf_out << data; - if (!hf_out.good() ) { + if (!hf_out.good()) { err ("error: can't write to hashfile"); return 1; } hf_out.close(); - if (!hf_out.good() ) { + if (!hf_out.good()) { err ("error: couldn't close hashfile"); return 1; } @@ -600,7 +600,7 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, keyring&KR, algorithm_suite&AS) { //symmetric processing has its own function - if (symmetric.length() ) + if (symmetric.length()) return action_hash_sign (armor, symmetric); /* @@ -613,14 +613,14 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, * - clearsign (which is always armored) */ - if (clearsign && (detach.length() || armor) ) { + if (clearsign && (detach.length() || armor)) { err ("error: clearsign cannot be combined " "with armor or detach-sign"); return 1; } std::ofstream detf; - if (detach.length() ) { + if (detach.length()) { detf.open (detach == "-" ? "/dev/stdout" : detach.c_str(), std::ios::out | std::ios::binary); if (!detf) { @@ -640,15 +640,15 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (user, i->second.pub.name, i->first) ) { + if (keyspec_matches (user, i->second.pub.name, i->first)) { /* * also match having signature alg availability, * because it saves time when you only have one locally * available signature privkey. Also, no need to check * it again later. */ - if (!AS.count (i->second.pub.alg) ) continue; - if (!AS[i->second.pub.alg]->provides_signatures() ) + if (!AS.count (i->second.pub.alg)) continue; + if (!AS[i->second.pub.alg]->provides_signatures()) continue; if (u) { @@ -671,7 +671,7 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, bvector message; message.from_string (data); - if (msg.sign (message, u->pub.alg, u->pub.keyid, AS, KR, r) ) { + if (msg.sign (message, u->pub.alg, u->pub.keyid, AS, KR, r)) { err ("error: digital signature failed"); return 1; } @@ -689,9 +689,9 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, base64_encode (M->encode(), parts[1]); sencode_destroy (M); - out_bin (envelope_format (ENVELOPE_CLEARSIGN, parts, r) ); + out_bin (envelope_format (ENVELOPE_CLEARSIGN, parts, r)); - } else if (detach.length() ) { + } else if (detach.length()) { msg.message.from_string (MSG_DETACHED); sencode*M = msg.serialize(); data = M->encode(); @@ -705,12 +705,12 @@ int action_sign (const std::string&user, bool armor, const std::string&detach, } detf << data; - if (!detf.good() ) { + if (!detf.good()) { err ("error: could not write detached signature file"); return 1; } detf.close(); - if (!detf.good() ) { + if (!detf.good()) { err ("error: could not close detached signature file"); return 1; } @@ -745,7 +745,7 @@ int action_hash_verify (bool armor, const std::string&symmetric) } std::string hf_data; - if (!read_all_input (hf_data, hf_in) ) { + if (!read_all_input (hf_data, hf_in)) { err ("error: can't read hashfile"); return 1; } @@ -754,7 +754,7 @@ int action_hash_verify (bool armor, const std::string&symmetric) if (armor) { std::vector parts; std::string type; - if (!envelope_read (hf_data, 0, type, parts) ) { + if (!envelope_read (hf_data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -764,7 +764,7 @@ int action_hash_verify (bool armor, const std::string&symmetric) return 1; } - if (!base64_decode (parts[0], hf_data) ) { + if (!base64_decode (parts[0], hf_data)) { err ("error: malformed data"); return 1; } @@ -777,7 +777,7 @@ int action_hash_verify (bool armor, const std::string&symmetric) } hashfile hf; - if (!hf.unserialize (H) ) { + if (!hf.unserialize (H)) { err ("error: could not parse input structure"); return 1; } @@ -795,20 +795,20 @@ int action_verify (bool armor, const std::string&detach, keyring&KR, algorithm_suite&AS) { //symmetric processing has its own function - if (symmetric.length() ) + if (symmetric.length()) return action_hash_verify (armor, symmetric); /* * check flags validity, open detach if possible */ - if (clearsign && (detach.length() || armor) ) { + if (clearsign && (detach.length() || armor)) { err ("error: clearsign cannot be combined " "with armor or detach-sign"); return 1; } std::ifstream detf; - if (detach.length() ) { + if (detach.length()) { detf.open (detach == "-" ? "/dev/stdin" : detach.c_str(), std::ios::in | std::ios::binary); if (!detf) { @@ -831,7 +831,7 @@ int action_verify (bool armor, const std::string&detach, std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -842,7 +842,7 @@ int action_verify (bool armor, const std::string&detach, } std::string sig; - if (!base64_decode (parts[1], sig) ) { + if (!base64_decode (parts[1], sig)) { err ("error: malformed data"); return 1; } @@ -853,7 +853,7 @@ int action_verify (bool armor, const std::string&detach, return 1; } - if (!msg.unserialize (M) ) { + if (!msg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -869,10 +869,10 @@ int action_verify (bool armor, const std::string&detach, msg.message.from_string (parts[0]); - } else if (detach.length() ) { + } else if (detach.length()) { std::string sig; - if (!read_all_input (sig, detf) ) { + if (!read_all_input (sig, detf)) { err ("error: can't read detached signature file"); return 1; } @@ -882,7 +882,7 @@ int action_verify (bool armor, const std::string&detach, if (armor) { std::vector parts; std::string type; - if (!envelope_read (sig, 0, type, parts) ) { + if (!envelope_read (sig, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -892,7 +892,7 @@ int action_verify (bool armor, const std::string&detach, return 1; } - if (!base64_decode (parts[0], sig) ) { + if (!base64_decode (parts[0], sig)) { err ("error: malformed data"); return 1; } @@ -904,7 +904,7 @@ int action_verify (bool armor, const std::string&detach, return 1; } - if (!msg.unserialize (M) ) { + if (!msg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -926,7 +926,7 @@ int action_verify (bool armor, const std::string&detach, std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -936,7 +936,7 @@ int action_verify (bool armor, const std::string&detach, return 1; } - if (!base64_decode (parts[0], data) ) { + if (!base64_decode (parts[0], data)) { err ("error: malformed data"); return 1; } @@ -945,13 +945,13 @@ int action_verify (bool armor, const std::string&detach, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); - if (!armor && envelope_lookalike (data) ) + if (!armor && envelope_lookalike (data)) err ("notice: input looks ascii-armored, " "try using the armor option"); return 1; } - if (!msg.unserialize (M) ) { + if (!msg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -985,8 +985,8 @@ int action_verify (bool armor, const std::string&detach, return 2; //missing key flag } - if ( (!AS.count (msg.alg_id) ) - || (!AS[msg.alg_id]->provides_signatures() ) ) { + if ( (!AS.count (msg.alg_id)) + || (!AS[msg.alg_id]->provides_signatures())) { err ("error: verification algorithm unsupported"); err ("info: requires algorithm " << msg.alg_id << " with signature support"); @@ -1003,7 +1003,7 @@ int action_verify (bool armor, const std::string&detach, err (" verification status: " << (r == 0 ? "GOOD signature ;-)" : - "BAD signature :-(") ); + "BAD signature :-(")); if (r) { if (!yes) { @@ -1049,9 +1049,9 @@ int action_sign_encrypt (const std::string&user, const std::string&recipient, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (user, i->second.pub.name, i->first) ) { - if (!AS.count (i->second.pub.alg) ) continue; - if (!AS[i->second.pub.alg]->provides_signatures() ) + if (keyspec_matches (user, i->second.pub.name, i->first)) { + if (!AS.count (i->second.pub.alg)) continue; + if (!AS[i->second.pub.alg]->provides_signatures()) continue; if (u) { @@ -1071,9 +1071,9 @@ int action_sign_encrypt (const std::string&user, const std::string&recipient, for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (recipient, i->second.name, i->first) ) { - if (!AS.count (i->second.alg) ) continue; - if (!AS[i->second.alg]->provides_encryption() ) + if (keyspec_matches (recipient, i->second.name, i->first)) { + if (!AS.count (i->second.alg)) continue; + if (!AS[i->second.alg]->provides_encryption()) continue; if (recip) { @@ -1085,9 +1085,9 @@ int action_sign_encrypt (const std::string&user, const std::string&recipient, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (recipient, i->second.pub.name, i->first) ) { - if (!AS.count (i->second.pub.alg) ) continue; - if (!AS[i->second.pub.alg]->provides_encryption() ) + if (keyspec_matches (recipient, i->second.pub.name, i->first)) { + if (!AS.count (i->second.pub.alg)) continue; + if (!AS[i->second.pub.alg]->provides_encryption()) continue; if (recip) { @@ -1110,7 +1110,7 @@ int action_sign_encrypt (const std::string&user, const std::string&recipient, bvector bv; bv.from_string (data); - if (smsg.sign (bv, u->pub.alg, u->pub.keyid, AS, KR, r) ) { + if (smsg.sign (bv, u->pub.alg, u->pub.keyid, AS, KR, r)) { err ("error: digital signature failed"); return 1; } @@ -1122,7 +1122,7 @@ int action_sign_encrypt (const std::string&user, const std::string&recipient, //encrypt it encrypted_msg emsg; bv.from_string (data); - if (emsg.encrypt (bv, recip->alg, recip->keyid, AS, KR, r) ) { + if (emsg.encrypt (bv, recip->alg, recip->keyid, AS, KR, r)) { err ("error: encryption failed"); return 1; } @@ -1152,7 +1152,7 @@ int action_decrypt_verify (bool armor, bool yes, if (armor) { std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -1161,7 +1161,7 @@ int action_decrypt_verify (bool armor, bool yes, err ("error: wrong envelope format"); return 1; } - if (!base64_decode (parts[0], data) ) { + if (!base64_decode (parts[0], data)) { err ("error: malformed data"); return 1; } @@ -1170,14 +1170,14 @@ int action_decrypt_verify (bool armor, bool yes, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); - if (!armor && envelope_lookalike (data) ) + if (!armor && envelope_lookalike (data)) err ("notice: input looks ascii-armored, " "try using the armor option"); return 1; } encrypted_msg emsg; - if (!emsg.unserialize (M) ) { + if (!emsg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -1196,8 +1196,8 @@ int action_decrypt_verify (bool armor, bool yes, return 2; //missing key flag } - if ( (!AS.count (emsg.alg_id) ) - || (!AS[emsg.alg_id]->provides_encryption() ) ) { + if ( (!AS.count (emsg.alg_id)) + || (!AS[emsg.alg_id]->provides_encryption())) { err ("error: decryption algorithm unsupported"); err ("info: requires algorithm " << emsg.alg_id << " with encryption support"); @@ -1205,12 +1205,12 @@ int action_decrypt_verify (bool armor, bool yes, } bvector bv; - if (emsg.decrypt (bv, AS, KR) ) { + if (emsg.decrypt (bv, AS, KR)) { err ("error: decryption failed"); return 1; } - if (!bv.to_string (data) ) { + if (!bv.to_string (data)) { err ("error: malformed data"); return 1; } @@ -1229,7 +1229,7 @@ int action_decrypt_verify (bool armor, bool yes, } signed_msg smsg; - if (!smsg.unserialize (M) ) { + if (!smsg.unserialize (M)) { err ("error: could not parse input structure"); sencode_destroy (M); return 1; @@ -1258,8 +1258,8 @@ int action_decrypt_verify (bool armor, bool yes, return 2; //missing key flag } - if ( (!AS.count (smsg.alg_id) ) - || (!AS[smsg.alg_id]->provides_signatures() ) ) { + if ( (!AS.count (smsg.alg_id)) + || (!AS[smsg.alg_id]->provides_signatures())) { err ("error: verification algorithm unsupported"); err ("info: requires algorithm " << smsg.alg_id << " with signature support"); @@ -1276,7 +1276,7 @@ int action_decrypt_verify (bool armor, bool yes, err (" verification status: " << (r == 0 ? "GOOD signature ;-)" : - "BAD signature :-(") ); + "BAD signature :-(")); if (r) { if (!yes) { @@ -1350,10 +1350,10 @@ static void output_key (bool fp, if (!fp) out (ident << '\t' << alg << '\t' << '@' << keyid.substr (0, 22) << "...\t" - << escape_key_name (name) ); + << escape_key_name (name)); else { - out ( longid << " with algorithm " << alg - << ", name `" << escape_key_name (name) << "'"); + out (longid << " with algorithm " << alg + << ", name `" << escape_key_name (name) << "'"); std::cout << " fingerprint "; for (size_t j = 0; j < keyid.length(); ++j) { @@ -1375,7 +1375,7 @@ int action_list (bool nice_fingerprint, const std::string&filter, i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) + if (keyspec_matches (filter, i->second.pub.name, i->first)) output_key (nice_fingerprint, "pubkey", "public key in keypair", @@ -1386,7 +1386,7 @@ int action_list (bool nice_fingerprint, const std::string&filter, for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) + if (keyspec_matches (filter, i->second.name, i->first)) output_key (nice_fingerprint, "pubkey", "public key", i->second.alg, i->first, @@ -1406,7 +1406,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, if (armor) { std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -1416,7 +1416,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, return 1; } - if (!base64_decode (parts[0], data) ) { + if (!base64_decode (parts[0], data)) { err ("error: malformed data"); return 1; } @@ -1425,21 +1425,21 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, sencode*S = sencode_decode (data); if (!S) { err ("error: could not parse input sencode"); - if (!armor && envelope_lookalike (data) ) + if (!armor && envelope_lookalike (data)) err ("notice: input looks ascii-armored, " "try using the armor option"); return 1; } keyring::pubkey_storage p; - if (!keyring::parse_pubkeys (S, p) ) { + if (!keyring::parse_pubkeys (S, p)) { err ("error: could not parse input structure"); sencode_destroy (S); return 1; } sencode_destroy (S); - if (!p.size() ) { + if (!p.size()) { err ("notice: keyring was empty"); return 0; } @@ -1448,7 +1448,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, for (keyring::pubkey_storage::iterator i = p.begin(), e = p.end(); i != e; ++i) { if (keyspec_matches (filter, i->second.name, - i->first) ) + i->first)) output_key (fp, "pubkey", "public key", i->second.alg, i->first, @@ -1463,11 +1463,11 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, int rewrites = 0, privs = 0; for (keyring::pubkey_storage::iterator i = p.begin(), e = p.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) { - if (KR.pairs.count (i->first) ) { + if (keyspec_matches (filter, i->second.name, i->first)) { + if (KR.pairs.count (i->first)) { ++privs; ++rewrites; - } else if (KR.pubs.count (i->first) ) { + } else if (KR.pubs.count (i->first)) { ++rewrites; } } @@ -1484,7 +1484,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, //merge into KR. Also prevent keyID collisions for (keyring::pubkey_storage::iterator i = p.begin(), e = p.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) { + if (keyspec_matches (filter, i->second.name, i->first)) { KR.remove_pubkey (i->first); KR.remove_keypair (i->first); KR.store_pubkey (i->first, @@ -1494,7 +1494,7 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, } } - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -1514,9 +1514,9 @@ int action_export (bool armor, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) { + if (keyspec_matches (filter, i->second.pub.name, i->first)) { s[i->first] = i->second.pub; - if (name.length() ) + if (name.length()) s[i->first].name = name; } } @@ -1524,14 +1524,14 @@ int action_export (bool armor, for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) { + if (keyspec_matches (filter, i->second.name, i->first)) { s[i->first] = i->second; - if (name.length() ) + if (name.length()) s[i->first].name = name; } } - if (!s.size() ) { + if (!s.size()) { err ("error: no such public keys"); return 1; } @@ -1565,7 +1565,7 @@ int action_delete (bool yes, const std::string & filter, keyring & KR) for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) - if (keyspec_matches (filter, i->second.name, i->first) ) { + if (keyspec_matches (filter, i->second.name, i->first)) { ++kc; todel.push_back (i->first); } @@ -1585,7 +1585,7 @@ int action_delete (bool yes, const std::string & filter, keyring & KR) i = todel.begin(), e = todel.end(); i != e; ++i) KR.remove_pubkey (*i); - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -1598,7 +1598,7 @@ int action_rename (bool yes, const std::string & filter, const std::string & name, keyring & KR) { - if (!name.length() ) { + if (!name.length()) { err ("error: missing new name specification"); return 1; } @@ -1609,7 +1609,7 @@ int action_rename (bool yes, for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) + if (keyspec_matches (filter, i->second.name, i->first)) ++kc; } if (!kc) { @@ -1628,11 +1628,11 @@ int action_rename (bool yes, for (keyring::pubkey_storage::iterator i = KR.pubs.begin(), e = KR.pubs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.name, i->first) ) + if (keyspec_matches (filter, i->second.name, i->first)) i->second.name = name; } - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -1651,7 +1651,7 @@ int action_list_sec (bool nice_fingerprint, const std::string & filter, i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) + if (keyspec_matches (filter, i->second.pub.name, i->first)) output_key (nice_fingerprint, "keypair", "key pair", i->second.pub.alg, i->first, @@ -1671,7 +1671,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, if (armor) { std::string type; std::vector parts; - if (!envelope_read (data, 0, type, parts) ) { + if (!envelope_read (data, 0, type, parts)) { err ("error: no data envelope found"); return 1; } @@ -1681,7 +1681,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, return 1; } - if (!base64_decode (parts[0], data) ) { + if (!base64_decode (parts[0], data)) { err ("error: malformed data"); return 1; } @@ -1690,21 +1690,21 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, sencode*S = sencode_decode (data); if (!S) { err ("error: could not parse input sencode"); - if (!armor && envelope_lookalike (data) ) + if (!armor && envelope_lookalike (data)) err ("notice: input looks ascii-armored, " "try using the armor option"); return 1; } keyring::keypair_storage s; - if (!keyring::parse_keypairs (S, s) ) { + if (!keyring::parse_keypairs (S, s)) { err ("error: could not parse input structure"); sencode_destroy (S); return 1; } sencode_destroy (S); - if (!s.size() ) { + if (!s.size()) { err ("notice: keyring was empty"); return 0; } @@ -1713,7 +1713,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, for (keyring::keypair_storage::iterator i = s.begin(), e = s.end(); i != e; ++i) { if (keyspec_matches (filter, i->second.pub.name, - i->first) ) + i->first)) output_key (fp, "keypair", "key pair", i->second.pub.alg, i->first, @@ -1729,7 +1729,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, i = s.begin(), e = s.end(); i != e; ++i) { if (keyspec_matches (filter, i->second.pub.name, i->first) && (KR.pubs.count (i->first) - || KR.pairs.count (i->first) ) ) + || KR.pairs.count (i->first))) ++rewrites; } @@ -1743,7 +1743,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, //merge into KR. Also prevent keyID collisions for (keyring::keypair_storage::iterator i = s.begin(), e = s.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) { + if (keyspec_matches (filter, i->second.pub.name, i->first)) { KR.remove_pubkey (i->first); KR.remove_keypair (i->first); KR.store_keypair (i->first, @@ -1754,7 +1754,7 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, } } - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -1773,14 +1773,14 @@ int action_export_sec (bool armor, bool yes, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) { + if (keyspec_matches (filter, i->second.pub.name, i->first)) { s[i->first] = i->second; - if (name.length() ) + if (name.length()) s[i->first].pub.name = name; } } - if (!s.size() ) { + if (!s.size()) { err ("error: no such secret"); return 1; } @@ -1821,7 +1821,7 @@ int action_delete_sec (bool yes, const std::string & filter, keyring & KR) for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) - if (keyspec_matches (filter, i->second.pub.name, i->first) ) { + if (keyspec_matches (filter, i->second.pub.name, i->first)) { ++kc; todel.push_back (i->first); } @@ -1842,7 +1842,7 @@ int action_delete_sec (bool yes, const std::string & filter, keyring & KR) i = todel.begin(), e = todel.end(); i != e; ++i) KR.remove_keypair (*i); - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } @@ -1855,7 +1855,7 @@ int action_rename_sec (bool yes, const std::string & filter, const std::string & name, keyring & KR) { - if (!name.length() ) { + if (!name.length()) { err ("error: missing new name specification"); return 1; } @@ -1866,7 +1866,7 @@ int action_rename_sec (bool yes, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) + if (keyspec_matches (filter, i->second.pub.name, i->first)) ++kc; } if (!kc) { @@ -1885,11 +1885,11 @@ int action_rename_sec (bool yes, for (keyring::keypair_storage::iterator i = KR.pairs.begin(), e = KR.pairs.end(); i != e; ++i) { - if (keyspec_matches (filter, i->second.pub.name, i->first) ) + if (keyspec_matches (filter, i->second.pub.name, i->first)) i->second.pub.name = name; } - if (!KR.save() ) { + if (!KR.save()) { err ("error: couldn't save keyring"); return 1; } diff --git a/src/algos_enc.cpp b/src/algos_enc.cpp index 90deae1..59e3800 100644 --- a/src/algos_enc.cpp +++ b/src/algos_enc.cpp @@ -30,7 +30,7 @@ static int mceqd_create_keypair (sencode**pub, sencode**priv, prng&rng) mce_qd::pubkey Pub; mce_qd::privkey Priv; - if (mce_qd::generate (Pub, Priv, rng, m, T, b, d) ) + if (mce_qd::generate (Pub, Priv, rng, m, T, b, d)) return 1; *pub = Pub.serialize(); @@ -121,7 +121,7 @@ static void message_pad (const bvector&in, std::vector&out, //pad with random bits to whole byte unsigned char rtmp = rng.random (256); for (; i & 0x7; ++i) - if (rtmp >> (i & 0x7) ) + if (rtmp >> (i & 0x7)) out[i >> 3] |= 1 << (i & 0x7); //append message overflow size @@ -149,7 +149,7 @@ static bool message_unpad (std::vector in, bvector&out, hash_func&pad_hash) { //check byte padding sizes - if (!in.size() ) return false; + if (!in.size()) return false; //get rid of the byte padding uint padsize_begin, padsize_end; @@ -158,7 +158,7 @@ static bool message_unpad (std::vector in, bvector&out, padsize_end = in[in.size() - 1]; //check if it really fits //(2 bytes padding + 1 byte min padded msg length) - if ( (uint) padsize_begin + (uint) padsize_end + 3 > in.size() ) + if ( (uint) padsize_begin + (uint) padsize_end + 3 > in.size()) return false; //get rid of beginning padding @@ -183,15 +183,15 @@ static bool message_unpad (std::vector in, bvector&out, if (bit_overflow >= 8) return false; //check if there's byte with overflow bits - if (bit_overflow && (in_end < 2) ) return false; + if (bit_overflow && (in_end < 2)) return false; //convert to bvector - uint msg_size = ( (in_end - (bit_overflow ? 2 : 1) ) << 3) + uint msg_size = ( (in_end - (bit_overflow ? 2 : 1)) << 3) + bit_overflow; out.clear(); out.resize (msg_size); for (uint i = 0; i < msg_size; ++i) - out[i] = 1 & (in[i >> 3] >> (i & 0x7) ); + out[i] = 1 & (in[i >> 3] >> (i & 0x7)); return true; } @@ -211,13 +211,13 @@ static bool message_unpad (std::vector in, bvector&out, */ template < class pubkey_type, - int plainsize, - int ciphersize, - int errorcount, - class hash_type, - class pad_hash_type, - class scipher, - int ranksize > + int plainsize, + int ciphersize, + int errorcount, + class hash_type, + class pad_hash_type, + class scipher, + int ranksize > static int fo_encrypt (const bvector&plain, bvector&cipher, sencode* pubkey, prng&rng) { @@ -225,7 +225,7 @@ static int fo_encrypt (const bvector&plain, bvector&cipher, //load the key pubkey_type Pub; - if (!Pub.unserialize (pubkey) ) return 1; + if (!Pub.unserialize (pubkey)) return 1; //verify that key parameters match our scheme if (Pub.plain_size() != plainsize) return 2; @@ -245,7 +245,7 @@ static int fo_encrypt (const bvector&plain, bvector&cipher, //create the base for error vector std::vector H, M2; M2 = M; - M2.insert (M2.end(), K.begin(), K.end() ); + M2.insert (M2.end(), K.begin(), K.end()); hash_type hf; H = hf (M2); @@ -253,7 +253,7 @@ static int fo_encrypt (const bvector&plain, bvector&cipher, bvector ev_rank; ev_rank.resize (ranksize); for (i = 0; i < ranksize; ++i) - ev_rank[i] = 1 & (H[ (i >> 3) % H.size()] >> (i & 0x7) ); + ev_rank[i] = 1 & (H[ (i >> 3) % H.size()] >> (i & 0x7)); bvector ev; ev_rank.colex_unrank (ev, ciphersize, errorcount); @@ -261,10 +261,10 @@ static int fo_encrypt (const bvector&plain, bvector&cipher, //prepare plaintext bvector mce_plain; mce_plain.resize (plainsize); - for (i = 0; i < plainsize; ++i) mce_plain[i] = 1 & (K[i >> 3] >> (i & 0x7) ); + for (i = 0; i < plainsize; ++i) mce_plain[i] = 1 & (K[i >> 3] >> (i & 0x7)); //run McEliece - if (Pub.encrypt (mce_plain, cipher, ev) ) return 5; + if (Pub.encrypt (mce_plain, cipher, ev)) return 5; //encrypt the message part scipher sc; @@ -276,21 +276,21 @@ static int fo_encrypt (const bvector&plain, bvector&cipher, for (i = 0; i < M.size(); ++i) M[i] = M[i] ^ sc.gen(); //append the message part to the ciphertext - cipher.resize (ciphersize + (M.size() << 3) ); + cipher.resize (ciphersize + (M.size() << 3)); for (i = 0; i < (M.size() << 3); ++i) - cipher[ciphersize + i] = 1 & (M[i >> 3] >> (i & 0x7) ); + cipher[ciphersize + i] = 1 & (M[i >> 3] >> (i & 0x7)); return 0; } template < class privkey_type, - int plainsize, - int ciphersize, - int errorcount, - class hash_type, - class pad_hash_type, - class scipher, - int ranksize > + int plainsize, + int ciphersize, + int errorcount, + class hash_type, + class pad_hash_type, + class scipher, + int ranksize > static int fo_decrypt (const bvector&cipher, bvector&plain, sencode* privkey) { @@ -298,9 +298,9 @@ static int fo_decrypt (const bvector&cipher, bvector&plain, //load the key privkey_type Priv; - if (!Priv.unserialize (privkey) ) return 1; + if (!Priv.unserialize (privkey)) return 1; - if (Priv.prepare() ) return 100; + if (Priv.prepare()) return 100; //verify that key parameters match the scheme if (Priv.plain_size() != plainsize) return 2; @@ -371,7 +371,7 @@ static int fo_decrypt (const bvector&cipher, bvector&plain, //compute the hash of K+M std::vectorH, M2; M2 = M; - M2.insert (M2.end(), K.begin(), K.end() ); + M2.insert (M2.end(), K.begin(), K.end()); hash_type hf; H = hf (M2); @@ -381,13 +381,13 @@ static int fo_decrypt (const bvector&cipher, bvector&plain, ev_rank.resize (ranksize, 0); for (i = 0; i < ranksize; ++i) if (ev_rank[i] != (1 & (H[ (i >> 3) % H.size()] - >> (i & 0x7) ) ) ) + >> (i & 0x7)))) return 7; //if the message seems okay, unpad and return it. pad_hash_type phf; - if (!message_unpad (M, plain, phf) ) return 8; + if (!message_unpad (M, plain, phf)) return 8; return 0; } diff --git a/src/algos_sig.cpp b/src/algos_sig.cpp index c12d229..a3cfec1 100644 --- a/src/algos_sig.cpp +++ b/src/algos_sig.cpp @@ -83,7 +83,7 @@ static void msg_pad (const bvector&in, std::vector&out, size_t minsize) */ template < int h, int l, int hs, - class message_hash, class tree_hash, class generator > + class message_hash, class tree_hash, class generator > static int fmtseq_generic_sign (const bvector&msg, bvector&sig, sencode**privkey, @@ -92,11 +92,11 @@ static int fmtseq_generic_sign (const bvector&msg, { //load the key fmtseq::privkey Priv; - if (!Priv.unserialize (*privkey) ) return 1; + if (!Priv.unserialize (*privkey)) return 1; //check parameters if ( (Priv.h != h) || (Priv.l != l) - || (Priv.hs != hs) ) return 2; + || (Priv.hs != hs)) return 2; //prepare the message and hash it std::vector M, H; @@ -107,12 +107,12 @@ static int fmtseq_generic_sign (const bvector&msg, //convert to bvector bvector hash; hash.resize (hs, 0); - for (uint i = 0; i < hs; ++i) hash[i] = 1 & (H[i >> 3] >> (i & 0x7) ); + for (uint i = 0; i < hs; ++i) hash[i] = 1 & (H[i >> 3] >> (i & 0x7)); //make a signature tree_hash hf; generator g; - if (Priv.sign (hash, sig, hf, g) ) return 3; + if (Priv.sign (hash, sig, hf, g)) return 3; //if it went okay, refresh the privkey sencode* new_pk = Priv.serialize(); @@ -132,10 +132,10 @@ static int fmtseq_generic_verify (const bvector&sig, { //load the key fmtseq::pubkey Pub; - if (!Pub.unserialize (pubkey) ) return 1; + if (!Pub.unserialize (pubkey)) return 1; //check parameters - if ( (Pub.H != h * l) || (Pub.hs != hs) ) return 2; + if ( (Pub.H != h * l) || (Pub.hs != hs)) return 2; //prepare the message and hash it std::vector M, H; @@ -146,11 +146,11 @@ static int fmtseq_generic_verify (const bvector&sig, //convert to bvector bvector hash; hash.resize (hs, 0); - for (uint i = 0; i < hs; ++i) hash[i] = 1 & (H[i >> 3] >> (i & 0x7) ); + for (uint i = 0; i < hs; ++i) hash[i] = 1 & (H[i >> 3] >> (i & 0x7)); //check the signature tree_hash hf; - if (Pub.verify (sig, hash, hf) ) return 3; + if (Pub.verify (sig, hash, hf)) return 3; //otherwise the sig is okay! return 0; @@ -165,7 +165,7 @@ static int fmtseq_create_keypair (sencode**pub, sencode**priv, prng&rng) treehash hf; generator g; - if (fmtseq::generate (Pub, Priv, rng, hf, g, hs, h, l) ) + if (fmtseq::generate (Pub, Priv, rng, hf, g, hs, h, l)) return 1; *pub = Pub.serialize(); diff --git a/src/arcfour.h b/src/arcfour.h index 7fbea87..c5ff3ce 100644 --- a/src/arcfour.h +++ b/src/arcfour.h @@ -35,7 +35,7 @@ public: I = J = 0; S.resize (Ssize); mask = ~ (inttype) 0; - if ( (inttype) (1 << bits) ) mask %= 1 << bits; + if ( (inttype) (1 << bits)) mask %= 1 << bits; for (size_t i = 0; i < Ssize; ++i) S[i] = i; } @@ -55,7 +55,7 @@ public: i <= mask; ++i, ++keypos) { if (keypos >= end) keypos = begin; //rotate - j = (j + S[i] + (*keypos) ) & mask; + j = (j + S[i] + (*keypos)) & mask; t = S[j]; S[j] = S[i]; S[i] = t; @@ -86,7 +86,7 @@ public: void gen (size_t n, std::vector&out) { out.resize (n); - gen (n, & (out[0]) ); + gen (n, & (out[0])); } size_t key_size() { diff --git a/src/base64.cpp b/src/base64.cpp index b422630..b2ea419 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -27,7 +27,7 @@ void base64_encode (const std::string& in, std::string&out, int cols) unsigned int acc = 0; int accbits = 0, idx = 0, idxmax = in.length(), col = 0; out.clear(); - out.reserve (idxmax + (2 * idxmax / 5) ); //reserve around 140% + out.reserve (idxmax + (2 * idxmax / 5)); //reserve around 140% while (idx < idxmax) { if (accbits < 6) { acc = (acc << 8) | (unsigned char) in[idx++]; @@ -37,14 +37,14 @@ void base64_encode (const std::string& in, std::string&out, int cols) accbits -= 6; out.push_back (b64str[ (acc >> accbits) & 0x3f]); - if (cols && ( (++col) >= cols) ) { + if (cols && ( (++col) >= cols)) { out.push_back ('\n'); col = 0; } } } if (accbits) { - out.push_back (b64str[ (acc << (6 - accbits) ) & 0x3f]); + out.push_back (b64str[ (acc << (6 - accbits)) & 0x3f]); if (accbits == 2) out.push_back ('='); if (accbits <= 4) out.push_back ('='); } @@ -149,7 +149,7 @@ 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); - if ( (idx < idxmax) && is_b64 (in[idx]) ) + if ( (idx < idxmax) && is_b64 (in[idx])) a[i] = in[idx]; else return false; ++idx; @@ -174,13 +174,13 @@ bool base64_decode (const std::string& in, std::string&out) //start parsing unsigned char c[4]; - while (eat_4 (in, idx, idxmax, c) ) { + while (eat_4 (in, idx, idxmax, c)) { for (int i = 0; i < 4; ++i) c[i] = b64d[c[i]]; // '=' gets converted to -1 //consistency checks - if ( (c[0] == -1) || (c[1] == -1) ) return false; - if ( (c[2] == -1) && (c[3] != -1) ) return false; + if ( (c[0] == -1) || (c[1] == -1)) return false; + if ( (c[2] == -1) && (c[3] != -1)) return false; tmp = (c[0] << 18) | (c[1] << 12); if (c[2] != -1) tmp |= c[2] << 6; diff --git a/src/bvector.cpp b/src/bvector.cpp index 5991df6..c8da9d1 100644 --- a/src/bvector.cpp +++ b/src/bvector.cpp @@ -29,35 +29,35 @@ uint bvector::hamming_weight() void bvector::add (const bvector&a) { - if (a.size() > size() ) resize (a.size(), 0); + if (a.size() > size()) resize (a.size(), 0); for (uint i = 0; i < a.size(); ++i) item (i) = item (i) ^ a[i]; } void bvector::add_range (const bvector&a, uint b, uint e) { - if (e > size() ) resize (e, 0); + if (e > size()) resize (e, 0); for (uint i = b; i < e; ++i) item (i) = item (i) ^ a[i]; } void bvector::add_offset (const bvector&a, uint offset) { - if (offset + a.size() > size() ) resize (offset + a.size(), 0); + if (offset + a.size() > size()) resize (offset + a.size(), 0); for (uint i = 0; i < a.size(); ++i) item (offset + i) = item (offset + i) ^ a[i]; } void bvector::set_block (const bvector&a, uint offset) { - if (offset + a.size() > size() ) resize (offset + a.size(), 0); + if (offset + a.size() > size()) resize (offset + a.size(), 0); for (uint i = 0; i < a.size(); ++i) item (offset + i) = a[i]; } void bvector::get_block (uint offset, uint bs, bvector&out) const { - if (offset + bs > size() ) return; + if (offset + bs > size()) return; out.resize (bs); for (uint i = 0; i < bs; ++i) out[i] = item (offset + i); } @@ -66,14 +66,14 @@ bool bvector::operator* (const bvector&a) { bool r = 0; uint s = size(), i; - if (s > a.size() ) s = a.size(); + if (s > a.size()) s = a.size(); for (i = 0; i < s; ++i) r ^= (item (i) &a[i]); return r; } bool bvector::zero() const { - for (uint i = 0; i < size(); ++i) if (item (i) ) return false; + for (uint i = 0; i < size(); ++i) if (item (i)) return false; return true; } @@ -83,7 +83,7 @@ void bvector::to_poly (polynomial&r, gf2m&fld) const if (size() % fld.m) return; //impossible r.resize (size() / fld.m, 0); for (uint i = 0; i < size(); ++i) - if (item (i) ) r[i / fld.m] |= (1 << (i % fld.m) ); + if (item (i)) r[i / fld.m] |= (1 << (i % fld.m)); } void bvector::from_poly (const polynomial&r, gf2m&fld) @@ -91,7 +91,7 @@ void bvector::from_poly (const polynomial&r, gf2m&fld) clear(); resize (r.size() *fld.m, 0); for (uint i = 0; i < size(); ++i) - item (i) = (r[i / fld.m] >> (i % fld.m) ) & 1; + item (i) = (r[i / fld.m] >> (i % fld.m)) & 1; } void bvector::to_poly_cotrace (polynomial&r, gf2m&fld) const @@ -101,7 +101,7 @@ void bvector::to_poly_cotrace (polynomial&r, gf2m&fld) const uint s = size() / fld.m; r.resize (s, 0); for (uint i = 0; i < size(); ++i) - if (item (i) ) r[i % s] |= (1 << (i / s) ); + if (item (i)) r[i % s] |= (1 << (i / s)); } void bvector::from_poly_cotrace (const polynomial&r, gf2m&fld) @@ -110,7 +110,7 @@ void bvector::from_poly_cotrace (const polynomial&r, gf2m&fld) uint s = r.size(); resize (s * fld.m, 0); for (uint i = 0; i < size(); ++i) - item (i) = (r[i % s] >> (i / s) ) & 1; + item (i) = (r[i % s] >> (i / s)) & 1; } bool bvector::to_string (std::string& out) const @@ -121,7 +121,7 @@ bool bvector::to_string (std::string& out) const out.resize (size() >> 3, 0); for (uint i = 0; i < size(); ++i) - if (item (i) ) out[i >> 3] |= (1 << (i & 0x7) ); + if (item (i)) out[i >> 3] |= (1 << (i & 0x7)); return true; } @@ -132,7 +132,7 @@ void bvector::from_string (const std::string&in) resize (in.length() << 3); for (uint i = 0; i < size(); ++i) - item (i) = (in[i >> 3] >> (i & 0x7) ) & 1; + item (i) = (in[i >> 3] >> (i & 0x7)) & 1; } /* @@ -204,7 +204,7 @@ static void combination_number (mpz_t& r, uint n, uint k) static void bvector_to_mpz (const bvector&v, mpz_t&r) { mpz_set_ui (r, 0); - mpz_realloc2 (r, v.size() ); + mpz_realloc2 (r, v.size()); for (uint i = 0; i < v.size(); ++i) if (v[i]) mpz_setbit (r, i); @@ -213,7 +213,7 @@ static void bvector_to_mpz (const bvector&v, mpz_t&r) static void mpz_to_bvector (mpz_t&x, bvector&r) { - r.resize (mpz_sizeinbase (x, 2) ); + r.resize (mpz_sizeinbase (x, 2)); for (uint i = 0; i < r.size(); ++i) r[i] = mpz_tstbit (x, i); } @@ -227,14 +227,14 @@ void bvector::colex_rank (bvector&r) const uint n = 0, k = 1; - while (item (n) ) ++n, ++k; //skip the "zeroes" on the beginning + while (item (n)) ++n, ++k; //skip the "zeroes" on the beginning ++n; //now n=k=1, comb=1 //non-zero positions for (; n < size(); ++n) { - if (item (n) ) { + if (item (n)) { //add combination number to result mpz_swap (t, res); mpz_add (res, t, comb); @@ -246,7 +246,7 @@ void bvector::colex_rank (bvector&r) const mpz_swap (t, comb); mpz_fdiv_q_ui (comb, t, n - k + 1); - if (item (n) ) { + if (item (n)) { //increase k in comb mpz_swap (t, comb); mpz_mul_ui (comb, t, n + 1 - k); //n has changed! diff --git a/src/cube_hash.h b/src/cube_hash.h index 7de86f8..b1eca2a 100644 --- a/src/cube_hash.h +++ b/src/cube_hash.h @@ -35,12 +35,12 @@ public: state.init(); for (i = 0; i + B <= a.size(); i += B) - state.process_block (& (a[i]) ); + state.process_block (& (a[i])); state.process_final_incomplete_block (& (a[i]), a.size() - i); std::vector result; result.resize (H, 0); - state.get_hash (& (result[0]) ); + state.get_hash (& (result[0])); return result; } }; @@ -72,8 +72,8 @@ public: bpos = 0; } } - while (apos + B <= asize ) { - state.process_block (& (a[apos]) ); + while (apos + B <= asize) { + state.process_block (& (a[apos])); apos += B; } for (; apos < asize; ++apos, ++bpos) @@ -84,7 +84,7 @@ public: state.process_final_incomplete_block (buf, bpos); std::vector result; result.resize (H, 0); - state.get_hash (& (result[0]) ); + state.get_hash (& (result[0])); return result; } }; diff --git a/src/cubehash_impl.h b/src/cubehash_impl.h index 8eb39be..828caa5 100644 --- a/src/cubehash_impl.h +++ b/src/cubehash_impl.h @@ -31,10 +31,10 @@ #define i16(cmd) for(i=0;i<16;++i) cmd; template < int I, //initialization rounds - int R, //rounds - int B, //input block size, less or equal 128 - int F, //finalization rounds - int H > //output hash size in *bytes*, not bits! less or equal 128. + int R, //rounds + int B, //input block size, less or equal 128 + int F, //finalization rounds + int H > //output hash size in *bytes*, not bits! less or equal 128. class cubehash_state { uint32_t X[32]; //the state @@ -45,13 +45,13 @@ class cubehash_state for (; n; --n) { i16 (X[i + 16] += X[i]); i16 (T[i ^ 8] = X[i]); - i16 (X[i] = ROT (T[i], 7, 32) ); + i16 (X[i] = ROT (T[i], 7, 32)); i16 (X[i] ^= X[i + 16]); i16 (T[i ^ 2] = X[i + 16]); i16 (X[i + 16] = T[i]); i16 (X[i + 16] += X[i]); i16 (T[i ^ 4] = X[i]); - i16 (X[i] = ROT (T[i], 11, 32) ); + i16 (X[i] = ROT (T[i], 11, 32)); i16 (X[i] ^= X[i + 16]); i16 (T[i ^ 1] = X[i + 16]); i16 (X[i + 16] = T[i]); @@ -87,7 +87,7 @@ public: X[i / 4] ^= * (uint32_t*) &data[i]; for (; i < B; ++i) - X[i / 4] ^= ( (uint32_t) (data[i]) ) << ( (i % 4) * 8); + X[i / 4] ^= ( (uint32_t) (data[i])) << ( (i % 4) * 8); rounds (R); } @@ -99,7 +99,7 @@ public: X[i / 4] ^= * (uint32_t*) &data[i]; for (; i < n; ++i) - X[i / 4] ^= ( (uint32_t) (data[i]) ) << ( (i % 4) * 8); + X[i / 4] ^= ( (uint32_t) (data[i])) << ( (i % 4) * 8); i++; X[i / 2] ^= ( (uint32_t) 0x80) << ( (i % 4) * 8); @@ -113,7 +113,7 @@ public: void get_hash (byte*out) { for (int i = 0; i < H; ++i) - out[i] = (X[i / 4] >> ( (i % 4) * 8) ) & 0xff; + out[i] = (X[i / 4] >> ( (i % 4) * 8)) & 0xff; } }; diff --git a/src/decoding.cpp b/src/decoding.cpp index 77cad40..7ab6b7a 100644 --- a/src/decoding.cpp +++ b/src/decoding.cpp @@ -23,7 +23,7 @@ void compute_goppa_error_locator (polynomial&syndrome, gf2m&fld, std::vector& sqInv, polynomial&out) { - if (syndrome.zero() ) { + if (syndrome.zero()) { //ensure no roots out.resize (1); out[0] = 1; @@ -52,7 +52,7 @@ void compute_goppa_error_locator (polynomial&syndrome, gf2m&fld, void compute_alternant_error_locator (polynomial&syndrome, gf2m&fld, uint t, polynomial&out) { - if (syndrome.zero() ) { + if (syndrome.zero()) { //ensure no roots out.resize (1); out[0] = 1; @@ -139,22 +139,22 @@ bool evaluate_error_locator_trace (polynomial&sigma, bvector&ev, gf2m&fld) std::set > stk; //"stack" - stk.insert (make_pair (0, sigma) ); + stk.insert (make_pair (0, sigma)); bool failed = false; - while (!stk.empty() ) { + while (!stk.empty()) { uint i = stk.begin()->first; polynomial cur = stk.begin()->second; - stk.erase (stk.begin() ); + stk.erase (stk.begin()); int deg = cur.degree(); if (deg <= 0) continue; if (deg == 1) { //found a linear factor - ev[fld.mult (cur[0], fld.inv (cur[1]) ) ] = 1; + ev[fld.mult (cur[0], fld.inv (cur[1])) ] = 1; continue; } @@ -163,7 +163,7 @@ bool evaluate_error_locator_trace (polynomial&sigma, bvector&ev, gf2m&fld) continue; } - if (trace[i].zero() ) { + if (trace[i].zero()) { //compute the trace if it isn't cached uint a = fld.exp (i); for (uint j = 0; j < fld.m; ++j) { @@ -177,8 +177,8 @@ bool evaluate_error_locator_trace (polynomial&sigma, bvector&ev, gf2m&fld) polynomial q, r; cur.divmod (t, q, r, fld); - stk.insert (make_pair (i + 1, t) ); - stk.insert (make_pair (i + 1, q) ); + stk.insert (make_pair (i + 1, t)); + stk.insert (make_pair (i + 1, q)); } return !failed; diff --git a/src/envelope.cpp b/src/envelope.cpp index 8ea57d5..3ac3ba4 100644 --- a/src/envelope.cpp +++ b/src/envelope.cpp @@ -33,9 +33,9 @@ inline static bool acceptable_char (char c) static bool acceptable_id (const std::string&a) { - if (!a.length() ) return false; + if (!a.length()) return false; for (size_t i = 0; i < a.length(); ++i) - if (!acceptable_char (a[i]) ) return false; + if (!acceptable_char (a[i])) return false; return true; } @@ -107,7 +107,7 @@ size_t envelope_read (const std::string&data, size_t offset, term = data.substr (eotype + 1, eoterm - eotype - 1); //verify that type&term are only of acceptable characters - if (!acceptable_id (type) || !acceptable_id (term) ) + if (!acceptable_id (type) || !acceptable_id (term)) continue; offset = eoterm + begin_suffix.length(); @@ -131,14 +131,14 @@ size_t envelope_read (const std::string&data, size_t offset, break; } - if ( cut_pos != data.npos && cut_pos < end_pos) { + if (cut_pos != data.npos && cut_pos < end_pos) { //there is cut out_parts.push_back - (data.substr (offset, cut_pos - offset) ); + (data.substr (offset, cut_pos - offset)); } else { //no cut, it's till the end out_parts.push_back - (data.substr (offset, end_pos - offset) ); + (data.substr (offset, end_pos - offset)); } if (cut_pos == data.npos) { @@ -191,8 +191,8 @@ std::string envelope_format (const std::string&type, bool good = true; std::vector::const_iterator i, e; for (i = parts.begin(), e = parts.end(); i != e; ++i) { - if ( i->find (cut_sep) != i->npos || - i->find (end_sep) != i->npos) { + if (i->find (cut_sep) != i->npos || + i->find (end_sep) != i->npos) { good = false; break; } diff --git a/src/fmtseq.cpp b/src/fmtseq.cpp index cdb234f..884937e 100644 --- a/src/fmtseq.cpp +++ b/src/fmtseq.cpp @@ -41,7 +41,7 @@ static void add_zero_checksum (bvector& v) uint z = s - v.hamming_weight(); //0's instead of 1's - v.resize (fmtseq_commitments (s) ); + v.resize (fmtseq_commitments (s)); while (z) { v[s] = z & 1; z >>= 1; @@ -52,7 +52,7 @@ static void add_zero_checksum (bvector& v) static void alloc_exist (privkey&priv) { priv.exist.resize (priv.l); - uint ts = (1 << (priv.h + 1) ) - 2; + uint ts = (1 << (priv.h + 1)) - 2; for (uint i = 0; i < priv.l; ++i) priv.exist[i].resize (ts); } @@ -75,7 +75,7 @@ static void alloc_desired (privkey&priv, hash_func&hf) priv.desired_stack.resize (priv.l - 1); priv.desired_progress.resize (priv.l - 1, 0); for (uint i = 0; i < priv.l - 1; ++i) { - priv.desired[i].resize ( (1 << (priv.h + 1) ) - 2); + priv.desired[i].resize ( (1 << (priv.h + 1)) - 2); for (uint j = 0; j < priv.desired[i].size(); ++j) priv.desired[i][j].resize (hf.size(), 0); } @@ -86,14 +86,14 @@ 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 >= ( (uint) 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; } static bool check_privkey (privkey&priv, hash_func&hf) { size_t i, j; - uint ts = (1 << (priv.h + 1) ) - 2; + uint ts = (1 << (priv.h + 1)) - 2; /* * check the content of privkey caches to prevent reading/writing @@ -110,19 +110,19 @@ static bool check_privkey (privkey&priv, hash_func&hf) //exist tree hash sizes must be OK for (j = 0; j < ts; ++j) if (priv.exist[i][j].size() - != hf.size() ) + != hf.size()) return false; } //check desired stuff - if (priv.desired_stack.size() < priv.desired.size() ) return false; - if (priv.desired_progress.size() < priv.desired.size() ) return false; + if (priv.desired_stack.size() < priv.desired.size()) return false; + if (priv.desired_progress.size() < priv.desired.size()) return false; for (i = 0; i < priv.desired.size(); ++i) { if (priv.desired[i].size() != ts) return false; for (j = 0; j < ts; ++j) if (priv.desired[i][j].size() - != hf.size() ) + != hf.size()) return false; } @@ -162,7 +162,7 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) * whole algorithm is kindof complex. Omitted for simplicity. */ - x.resize (hf.size() ); + x.resize (hf.size()); uint d_leaves, d_startpos, d_h; for (i = 0; i < priv.desired.size(); ++i) { @@ -172,15 +172,15 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) continue; //already done //create the leaf - d_startpos = (1 + (priv.sigs_used >> d_h) ) << d_h; + d_startpos = (1 + (priv.sigs_used >> d_h)) << d_h; uint leafid = d_startpos + priv.desired_progress[i]; prepare_keygen (generator, priv.SK, leafid); Y.clear(); for (j = 0; j < commitments; ++j) { - generator.gen (hf.size(), & (x[0]) ); + generator.gen (hf.size(), & (x[0])); x = hf (x); - Y.insert (Y.end(), x.begin(), x.end() ); + Y.insert (Y.end(), x.begin(), x.end()); } @@ -188,8 +188,8 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) &stk = priv.desired_stack[i]; stk.push_back (privkey::tree_stk_item - (0, priv.desired_progress[i], hf (Y) ) ); - store_desired (priv, i, stk.back() ); + (0, priv.desired_progress[i], hf (Y))); + store_desired (priv, i, stk.back()); ++priv.desired_progress[i]; @@ -202,17 +202,17 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) Y.clear(); Y.insert (Y.end(), (stk.end() - 2)->item.begin(), - (stk.end() - 2)->item.end() ); + (stk.end() - 2)->item.end()); Y.insert (Y.end(), (stk.end() - 1)->item.begin(), - (stk.end() - 1)->item.end() ); + (stk.end() - 1)->item.end()); uint l = stk.back().level + 1; uint p = stk.back().pos / 2; stk.pop_back(); stk.pop_back(); stk.push_back (privkey::tree_stk_item - (l, p, hf (Y) ) ); - store_desired (priv, i, stk.back() ); + (l, p, hf (Y))); + store_desired (priv, i, stk.back()); } } @@ -227,11 +227,11 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) uint idx = priv.l - i - 1; //ignore unused top levels - if (idx >= priv.desired.size() ) continue; + if (idx >= priv.desired.size()) continue; //if nothing changed, do nothing - if (! ( (subtree_changes >> (priv.h * (1 + idx) ) ) - & one_subtree_mask) ) continue; + if (! ( (subtree_changes >> (priv.h * (1 + idx))) + & one_subtree_mask)) continue; //move desired to exist priv.exist[idx] = priv.desired[idx]; @@ -242,9 +242,9 @@ static void update_privkey (privkey&priv, hash_func&hf, streamcipher&generator) //if there aren't more desired subtrees on this level, //strip it off. uint next_subtree_start = - (1 + (next_sigs_used >> ( (1 + idx) * priv.h) ) ) + (1 + (next_sigs_used >> ( (1 + idx) * priv.h))) << ( (1 + idx) * priv.h); - if (next_subtree_start >= ( (uint) 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); @@ -288,23 +288,23 @@ int fmtseq::generate (pubkey&pub, privkey&priv, uint commitments = fmtseq_commitments (hs); std::vector x, Y; - x.resize (hf.size() ); + x.resize (hf.size()); alloc_exist (priv); for (i = 0; i < sigs; ++i) { //generate commitments and concat publics into Y Y.clear(); - Y.reserve (commitments * hf.size() ); + Y.reserve (commitments * hf.size()); prepare_keygen (generator, priv.SK, i); for (j = 0; j < commitments; ++j) { - generator.gen (hf.size(), & (x[0]) ); + generator.gen (hf.size(), & (x[0])); x = hf (x); - Y.insert (Y.end(), x.begin(), x.end() ); + Y.insert (Y.end(), x.begin(), x.end()); } - stk.push_back (privkey::tree_stk_item (0, i, hf (Y) ) ); - store_exist (priv, stk.back() ); + stk.push_back (privkey::tree_stk_item (0, i, hf (Y))); + store_exist (priv, stk.back()); //try squashing the stack for (;;) { @@ -315,17 +315,17 @@ int fmtseq::generate (pubkey&pub, privkey&priv, Y.clear(); Y.insert (Y.end(), (stk.end() - 2)->item.begin(), - (stk.end() - 2)->item.end() ); + (stk.end() - 2)->item.end()); Y.insert (Y.end(), (stk.end() - 1)->item.begin(), - (stk.end() - 1)->item.end() ); + (stk.end() - 1)->item.end()); uint l = stk.back().level + 1; uint p = stk.back().pos / 2; stk.pop_back(); stk.pop_back(); stk.push_back (privkey::tree_stk_item - (l, p, hf (Y) ) ); - store_exist (priv, stk.back() ); + (l, p, hf (Y))); + store_exist (priv, stk.back()); } } @@ -362,13 +362,13 @@ int fmtseq::generate (pubkey&pub, privkey&priv, int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, streamcipher&generator) { - if (hash.size() != hash_size() ) return 2; - if (!sigs_remaining() ) { + if (hash.size() != hash_size()) return 2; + if (!sigs_remaining()) { err ("fmtseq notice: no signatures left"); return 2; } - if (!check_privkey (*this, hf) ) { + if (!check_privkey (*this, hf)) { err ("fmtseq: mangled privkey"); return 3; } @@ -381,20 +381,20 @@ int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, std::vector Sig, t; uint i; - t.resize (hf.size() ); + t.resize (hf.size()); - Sig.reserve (hf.size() * (commitments + h * l) ); + Sig.reserve (hf.size() * (commitments + h * l)); //first, compute the commitments and push them to the signature prepare_keygen (generator, SK, sigs_used); for (i = 0; i < commitments; ++i) { //generate x_i - generator.gen (hf.size(), & (t[0]) ); + generator.gen (hf.size(), & (t[0])); //if it's 0, publish y_i, else publish x_i if (!M2[i]) t = hf (t); //append it to signature - Sig.insert (Sig.end(), t.begin(), t.end() ); + Sig.insert (Sig.end(), t.begin(), t.end()); } //now retrieve the authentication path @@ -407,7 +407,7 @@ int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, expos = (pos ^ 1) % (1 << exlev); Sig.insert (Sig.end(), exist[exid][expos + (1 << exlev) - 2].begin(), - exist[exid][expos + (1 << exlev) - 2].end() ); + exist[exid][expos + (1 << exlev) - 2].end()); pos >>= 1; } @@ -418,7 +418,7 @@ int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, //convert to bits uint sig_no_start = (commitments + h * l) * hf.size() * 8; for (i = 0; i < sig_no_start; ++i) - sig[i] = 1 & (Sig[i / 8] >> (i % 8) ); + sig[i] = 1 & (Sig[i / 8] >> (i % 8)); //append signature number pos = sigs_used; @@ -431,10 +431,10 @@ int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, update_privkey (*this, hf, generator); //start moaning at around 1% of remaining signatures - if (!sigs_remaining() ) + if (!sigs_remaining()) err ("fmtseq notice: no signatures left, " "you should discard this key"); - else if (sigs_remaining() <= (uint) (1 << (h * l) ) / 100) + else if (sigs_remaining() <= (uint) (1 << (h * l)) / 100) err ("fmtseq notice: only " << sigs_remaining() << " signatures left, you should certify new keys"); else @@ -447,8 +447,8 @@ int privkey::sign (const bvector& hash, bvector& sig, hash_func& hf, int pubkey::verify (const bvector& sig, const bvector& hash, hash_func& hf) { uint i, j; - if (sig.size() != signature_size (hf) ) return 2; - if (hash.size() != hash_size() ) return 2; + if (sig.size() != signature_size (hf)) return 2; + if (hash.size() != hash_size()) return 2; uint commitments = fmtseq_commitments (hs); @@ -470,14 +470,14 @@ int pubkey::verify (const bvector& sig, const bvector& hash, hash_func& hf) Sig[i].resize (hf.size(), 0); for (j = 0; j < hf.size() * 8; ++j) if (sig[j + i * hf.size() * 8]) - Sig[i][j / 8] |= (1 << (j % 8) ); + Sig[i][j / 8] |= (1 << (j % 8)); } Y.clear(); for (i = 0; i < commitments; ++i) { if (M2[i]) t = hf (Sig[i]); //convert pk_i to sk_i at 1's else t = Sig[i]; //else it should already be pk_i - Y.insert (Y.end(), t.begin(), t.end() ); //append it to Y_i + Y.insert (Y.end(), t.begin(), t.end()); //append it to Y_i } //create the leaf @@ -489,11 +489,11 @@ int pubkey::verify (const bvector& sig, const bvector& hash, hash_func& hf) Y = Sig[commitments + i]; if ( (sig_no >> i) & 1) { //append path auth from left - Y.insert (Y.end(), t.begin(), t.end() ); + Y.insert (Y.end(), t.begin(), t.end()); t = hf (Y); } else { //append from right - t.insert (t.end(), Y.begin(), Y.end() ); + t.insert (t.end(), Y.begin(), Y.end()); t = hf (t); } diff --git a/src/fmtseq.h b/src/fmtseq.h index bf34607..cb6b233 100644 --- a/src/fmtseq.h +++ b/src/fmtseq.h @@ -74,7 +74,7 @@ public: int sign (const bvector&, bvector&, hash_func&, streamcipher&); uint sigs_remaining() { - return (1 << (h * l) ) - sigs_used; + return (1 << (h * l)) - sigs_used; } uint hash_size () { @@ -82,7 +82,7 @@ public: } uint signature_size (hash_func&hf) { - return ( (h * l + fmtseq_commitments (hs) ) * hf.size() * 8) + return ( (h * l + fmtseq_commitments (hs)) * hf.size() * 8) + (h * l); } @@ -103,7 +103,7 @@ public: } uint signature_size (hash_func&hf) { - return ( (H + fmtseq_commitments (hs) ) * hf.size() * 8) + H; + return ( (H + fmtseq_commitments (hs)) * hf.size() * 8) + H; } sencode* serialize(); diff --git a/src/gf2m.cpp b/src/gf2m.cpp index 7f4b560..cd8293b 100644 --- a/src/gf2m.cpp +++ b/src/gf2m.cpp @@ -36,8 +36,8 @@ uint gf2p_mod (uint a, uint p) { if (!p) return 0; int t, degp = gf2p_degree (p); - while ( (t = gf2p_degree (a) ) >= degp) { - a ^= (p << (t - degp) ); + while ( (t = gf2p_degree (a)) >= degp) { + a ^= (p << (t - degp)); } return a; } @@ -98,7 +98,7 @@ bool gf2m::create (uint M) */ for (uint t = (1 << m) + 1, e = 1 << (m + 1); t < e; t += 2) { - if (!is_irreducible_gf2_poly (t) ) continue; + if (!is_irreducible_gf2_poly (t)) continue; //try to prepare log and antilog tables log.resize (n, 0); diff --git a/src/gf2m.h b/src/gf2m.h index c4a0b62..8a95e73 100644 --- a/src/gf2m.h +++ b/src/gf2m.h @@ -42,7 +42,7 @@ public: } inline uint mult (uint a, uint b) { - if (! (a && b) ) return 0; + if (! (a && b)) return 0; return antilog[ (log[a] + log[b]) % (n - 1)]; } @@ -63,12 +63,12 @@ public: inline uint inv_square (uint a) { if (!a) return 0; - return antilog[ (2 * (n - 1 - log[a]) ) + return antilog[ (2 * (n - 1 - log[a])) % (n - 1)]; } inline uint div (uint a, uint b) { - if (! (a && b) ) return 0; + if (! (a && b)) return 0; return antilog[ (n - 1 - log[b] + log[a]) % (n - 1)]; } diff --git a/src/hash.cpp b/src/hash.cpp index fcb6451..fa32126 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -33,7 +33,7 @@ hash_proc::suite_t& hash_proc::suite() static factoryof type##_var; \ s[to_unicase(name)]=&type##_var; - if (s.empty() ) { + if (s.empty()) { do_hash ("CUBE512", cube512proc); #if HAVE_CRYPTOPP==1 do_hash ("RIPEMD128", rmd128proc); diff --git a/src/hash.h b/src/hash.h index 1f8f6c1..e3b9a9b 100644 --- a/src/hash.h +++ b/src/hash.h @@ -46,7 +46,7 @@ public: virtual ~hash_proc() {} void eat (const std::vector&a) { - return eat (& (a[0]), & (a[a.size()]) ); + return eat (& (a[0]), & (a[a.size()])); } typedef std::map*> suite_t; diff --git a/src/hashfile.cpp b/src/hashfile.cpp index 484612f..2d6ed2f 100644 --- a/src/hashfile.cpp +++ b/src/hashfile.cpp @@ -97,8 +97,8 @@ bool hashfile::create (istream&in) for (hashmap::iterator i = hm.begin(), e = hm.end(); i != e; ++i) i->second->eat (buf); - else if (in.eof() ) { - buf.resize (in.gcount() ); + else if (in.eof()) { + buf.resize (in.gcount()); for (hashmap::iterator i = hm.begin(), e = hm.end(); i != e; ++i) { i->second->eat (buf); @@ -115,13 +115,13 @@ int hashfile::verify (istream&in) fill_hashmap (hm_all); for (hashes_t::iterator i = hashes.begin(), e = hashes.end(); i != e; ++i) - if (hm_all.count (i->first) ) { + if (hm_all.count (i->first)) { hm[i->first] = hm_all[i->first]; hm_all[i->first].forget(); } - if (hm.empty() ) { + if (hm.empty()) { err ("notice: no verifiable hash found in hashfile"); return 2; } @@ -138,8 +138,8 @@ int hashfile::verify (istream&in) for (hashmap::iterator i = hm.begin(), e = hm.end(); i != e; ++i) i->second->eat (buf); - else if (in.eof() ) { - buf.resize (in.gcount() ); + else if (in.eof()) { + buf.resize (in.gcount()); for (hashmap::iterator i = hm.begin(), e = hm.end(); i != e; ++i) { i->second->eat (buf); @@ -151,12 +151,12 @@ int hashfile::verify (istream&in) int ok = 0, failed = 0; for (hashes_t::iterator i = hashes.begin(), e = hashes.end(); i != e; ++i) { - if (!hm.count (i->first) ) { + if (!hm.count (i->first)) { err ("hash verification: :-/ " << i->first << " not supported"); continue; } - if (i->second == hm[i->first]->finish() ) { + if (i->second == hm[i->first]->finish()) { ++ok; err ("hash verification: ;-) " << i->first << " is GOOD"); diff --git a/src/iohelpers.cpp b/src/iohelpers.cpp index 7636ec1..8423235 100644 --- a/src/iohelpers.cpp +++ b/src/iohelpers.cpp @@ -22,8 +22,8 @@ bool redirect_cin (const std::string& fn) { static std::ifstream alt_cin; alt_cin.open (fn.c_str(), std::ios::in | std::ios::binary); - if (alt_cin.fail() ) return false; - std::cin.rdbuf (alt_cin.rdbuf() ); + if (alt_cin.fail()) return false; + std::cin.rdbuf (alt_cin.rdbuf()); return true; } @@ -31,8 +31,8 @@ bool redirect_cout (const std::string& fn) { static std::ofstream alt_cout; alt_cout.open (fn.c_str(), std::ios::out | std::ios::binary); - if (alt_cout.fail() ) return false; - std::cout.rdbuf (alt_cout.rdbuf() ); + if (alt_cout.fail()) return false; + std::cout.rdbuf (alt_cout.rdbuf()); return true; } diff --git a/src/iohelpers.h b/src/iohelpers.h index 5d7b822..2a26523 100644 --- a/src/iohelpers.h +++ b/src/iohelpers.h @@ -53,9 +53,9 @@ bool read_all_input (output_seq&data, std::istream&input = std::cin) input.read (buf, readall_bufsize); if (input) data.insert (data.end(), buf, buf + readall_bufsize); - else if (input.eof() ) { + else if (input.eof()) { data.insert (data.end(), buf, - buf + input.gcount() ); + buf + input.gcount()); return true; } else return false; } diff --git a/src/keyring.cpp b/src/keyring.cpp index eb1d380..4d3771c 100644 --- a/src/keyring.cpp +++ b/src/keyring.cpp @@ -42,7 +42,7 @@ std::string keyring::get_keyid (const std::string&pubkey) std::vector tmp = hf (std::vector (&pubkey[0], - &pubkey[pubkey.length()]) ); + &pubkey[pubkey.length()])); r.resize (tmp.size() * 2, ' '); for (size_t i = 0; i < tmp.size(); ++i) { @@ -125,7 +125,7 @@ bool keyring::parse_keypairs (sencode*keypairs, keypair_storage&pairs) L = dynamic_cast (keypairs); if (!L) goto failure; - if (!L->items.size() ) goto failure; + if (!L->items.size()) goto failure; ID = dynamic_cast (L->items[0]); if (!ID) goto failure; if (ID->b != KEYPAIRS_ID) goto failure; @@ -144,7 +144,7 @@ bool keyring::parse_keypairs (sencode*keypairs, keypair_storage&pairs) *privkey = dynamic_cast (entry->items[2]), *pubkey = dynamic_cast (entry->items[3]); - if (! (ident && alg && privkey && pubkey) ) goto failure; + if (! (ident && alg && privkey && pubkey)) goto failure; std::string keyid = get_keyid (pubkey->b); sencode *priv, *pub; @@ -171,7 +171,7 @@ failure: sencode* keyring::serialize_keypairs (const keypair_storage&pairs) { sencode_list*L = new sencode_list(); - L->items.push_back (new sencode_bytes (KEYPAIRS_ID) ); + L->items.push_back (new sencode_bytes (KEYPAIRS_ID)); for (keypair_storage::const_iterator i = pairs.begin(), e = pairs.end(); @@ -180,8 +180,8 @@ sencode* keyring::serialize_keypairs (const keypair_storage&pairs) a->items.resize (4); a->items[0] = new sencode_bytes (i->second.pub.name); a->items[1] = new sencode_bytes (i->second.pub.alg); - a->items[2] = new sencode_bytes (i->second.privkey->encode() ); - a->items[3] = new sencode_bytes (i->second.pub.key->encode() ); + a->items[2] = new sencode_bytes (i->second.privkey->encode()); + a->items[3] = new sencode_bytes (i->second.pub.key->encode()); L->items.push_back (a); } @@ -198,7 +198,7 @@ bool keyring::parse_pubkeys (sencode* pubkeys, pubkey_storage&pubs) L = dynamic_cast (pubkeys); if (!L) goto failure; - if (!L->items.size() ) goto failure; + if (!L->items.size()) goto failure; ID = dynamic_cast (L->items[0]); if (!ID) goto failure; if (ID->b != PUBKEYS_ID) goto failure; @@ -217,7 +217,7 @@ bool keyring::parse_pubkeys (sencode* pubkeys, pubkey_storage&pubs) *alg = dynamic_cast (entry->items[1]), *pubkey = dynamic_cast (entry->items[2]); - if (! (ident && alg && pubkey) ) goto failure; + if (! (ident && alg && pubkey)) goto failure; std::string keyid = get_keyid (pubkey->b); sencode*key; @@ -237,7 +237,7 @@ failure: sencode* keyring::serialize_pubkeys (const pubkey_storage&pubs) { sencode_list*L = new sencode_list(); - L->items.push_back (new sencode_bytes (PUBKEYS_ID) ); + L->items.push_back (new sencode_bytes (PUBKEYS_ID)); for (pubkey_storage::const_iterator i = pubs.begin(), e = pubs.end(); @@ -246,7 +246,7 @@ sencode* keyring::serialize_pubkeys (const pubkey_storage&pubs) a->items.resize (3); a->items[0] = new sencode_bytes (i->second.name); a->items[1] = new sencode_bytes (i->second.alg); - a->items[2] = new sencode_bytes (i->second.key->encode() ); + a->items[2] = new sencode_bytes (i->second.key->encode()); L->items.push_back (a); } @@ -302,7 +302,7 @@ static bool ensure_empty_sencode_file (const std::string&fn, const std::string&ident) { struct stat st; - if (stat (fn.c_str(), &st) ) { + if (stat (fn.c_str(), &st)) { if (errno != ENOENT) return false; @@ -316,16 +316,16 @@ static bool ensure_empty_sencode_file (const std::string&fn, fd = creat (fn.c_str(), S_IRUSR | S_IWUSR); if (fd < 0) return false; ssize_t res = write (fd, emptyfile.c_str(), - emptyfile.length() ); - if (close (fd) ) return false; - if ( (size_t) res != emptyfile.length() ) return false; + emptyfile.length()); + if (close (fd)) return false; + if ( (size_t) res != emptyfile.length()) return false; } else { - if (!S_ISREG (st.st_mode) ) + if (!S_ISREG (st.st_mode)) return false; } - if (access (fn.c_str(), R_OK | W_OK) ) return false; + if (access (fn.c_str(), R_OK | W_OK)) return false; return true; } @@ -334,20 +334,20 @@ static bool prepare_user_dir (const std::string&dir) { //try to create the directory, continue if it's already there #ifdef WIN32 - if (mkdir (dir.c_str() ) ) { + if (mkdir (dir.c_str())) { #else - if (mkdir (dir.c_str(), 0777) ) { + if (mkdir (dir.c_str(), 0777)) { #endif if (errno != EEXIST) return false; } //and no matter what, verify it's there struct stat st; - if (stat (dir.c_str(), &st) ) + if (stat (dir.c_str(), &st)) return false; //and is really a directory. - if (!S_ISDIR (st.st_mode) ) + if (!S_ISDIR (st.st_mode)) return false; //finally create empty key storages and backups, if not present @@ -366,10 +366,10 @@ static sencode* file_get_sencode (const std::string&fn, { //check whether it is a file first struct stat st; - if (stat (fn.c_str(), &st) ) + if (stat (fn.c_str(), &st)) return NULL; - if (!S_ISREG (st.st_mode) ) + if (!S_ISREG (st.st_mode)) return NULL; //not we got the size, prepare buffer space @@ -388,10 +388,10 @@ static bool file_put_string (const std::string&fn, const std::string&data) { std::ofstream out (fn.c_str(), std::ios::out | std::ios::binary); if (!out) return false; - out.write (data.c_str(), data.length() ); - if (!out.good() ) return false; + out.write (data.c_str(), data.length()); + if (!out.good()) return false; out.close(); - if (!out.good() ) return false; + if (!out.good()) return false; return true; } @@ -483,7 +483,7 @@ bool keyring::open() { //ensure the existence of file structure std::string dir = get_user_dir(); - if (!prepare_user_dir (dir) ) return false; + if (!prepare_user_dir (dir)) return false; //create the lock std::string fn = dir + LOCK_FILENAME; @@ -493,7 +493,7 @@ bool keyring::open() #ifdef WIN32 //no locking on windows yet #else - if (flock (lockfd, LOCK_EX) ) { + if (flock (lockfd, LOCK_EX)) { ::close (lockfd); lockfd = -1; return false; @@ -543,7 +543,7 @@ bool keyring::close() if (lockfd < 0) return true; //nothing to close std::string fn = get_user_dir() + LOCK_FILENAME; - unlink (fn.c_str() ); + unlink (fn.c_str()); #ifdef WIN32 //no locking on windows yet diff --git a/src/keyring.h b/src/keyring.h index 7853764..d010167 100644 --- a/src/keyring.h +++ b/src/keyring.h @@ -90,7 +90,7 @@ public: static std::string get_keyid (const std::string& pubkey); static std::string get_keyid (sencode* pubkey) { - return get_keyid (pubkey->encode() ); + return get_keyid (pubkey->encode()); } static void clear_keypairs (keypair_storage&); @@ -103,8 +103,8 @@ public: pubkey_entry* get_pubkey (const std::string&keyid) { // "own first", but there should not be collisions. - if (pairs.count (keyid) ) return & (pairs[keyid].pub); - if (pubs.count (keyid) ) return & (pubs[keyid]); + if (pairs.count (keyid)) return & (pairs[keyid].pub); + if (pubs.count (keyid)) return & (pubs[keyid]); return NULL; } @@ -113,21 +113,21 @@ public: const std::string&alg, sencode*key) { - if (pairs.count (keyid) ) return false; - if (pubs.count (keyid) ) return false; + 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) { - if (pubs.count (keyid) ) { + if (pubs.count (keyid)) { sencode_destroy (pubs[keyid].key); pubs.erase (keyid); } } keypair_entry* get_keypair (const std::string&keyid) { - if (pairs.count (keyid) ) return & (pairs[keyid]); + if (pairs.count (keyid)) return & (pairs[keyid]); return NULL; } @@ -136,15 +136,15 @@ public: const std::string&alg, sencode*pubkey, sencode*privkey) { - if (pairs.count (keyid) ) return false; - if (pubs.count (keyid) ) return false; + if (pairs.count (keyid)) return false; + if (pubs.count (keyid)) return false; pairs[keyid] = keypair_entry (keyid, name, alg, pubkey, privkey); return true; } void remove_keypair (const std::string&keyid) { - if (pairs.count (keyid) ) { + if (pairs.count (keyid)) { sencode_destroy (pairs[keyid].pub.key); sencode_destroy (pairs[keyid].privkey); pairs.erase (keyid); diff --git a/src/main.cpp b/src/main.cpp index 003f4dd..08450aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -310,13 +310,13 @@ int main (int argc, char**argv) int exitval = 0; - if (input.length() && !redirect_cin (input) ) { + if (input.length() && !redirect_cin (input)) { progerr ("could not open input file"); exitval = 1; goto exit; } - if (output.length() && !redirect_cout (output) ) { + if (output.length() && !redirect_cout (output)) { progerr ("could not redirect to output file"); exitval = 1; goto exit; @@ -331,7 +331,7 @@ int main (int argc, char**argv) goto exit; } - if (symmetric.length() ) switch (action) { + if (symmetric.length()) switch (action) { case 'd': case 'e': case 'g': @@ -440,7 +440,7 @@ int main (int argc, char**argv) */ exit: - if (!KR.close() ) { + if (!KR.close()) { progerr ("could not close keyring, " "something weird is going to happen."); } diff --git a/src/matrix.cpp b/src/matrix.cpp index 9992330..6529223 100644 --- a/src/matrix.cpp +++ b/src/matrix.cpp @@ -80,7 +80,7 @@ bool matrix::compute_inversion (matrix&res, bool upper_tri, bool lower_tri) //we are computing with transposed matrices for simpler row ops uint s = width(); - if (s != height() ) return false; + if (s != height()) return false; matrix m, r; r.unit (s); this->compute_transpose (m); @@ -248,7 +248,7 @@ bool matrix::create_goppa_generator (matrix&g, const permutation&p) //generator construction from Barreto's PQC-4 slides p.21 p.permute (*this, t); t.get_right_square (sinv); - if (!sinv.compute_inversion (s) ) return false; //meant to be retried. + if (!sinv.compute_inversion (s)) return false; //meant to be retried. //TODO why multiply and THEN strip? s.mult (t); @@ -280,7 +280,7 @@ bool matrix::mult_vec_right (const bvector&a, bvector&r) r.clear(); r.resize (h, 0); for (uint i = 0; i < w; ++i) - if (a[i]) r.add (item (i) ); + if (a[i]) r.add (item (i)); return true; } diff --git a/src/matrix.h b/src/matrix.h index 71ca8ec..1fbde7a 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -41,7 +41,7 @@ public: } uint height() const { - if (size() ) return item (0).size(); + if (size()) return item (0).size(); return 0; } diff --git a/src/mce.cpp b/src/mce.cpp index f41f282..c3de535 100644 --- a/src/mce.cpp +++ b/src/mce.cpp @@ -35,7 +35,7 @@ int mce::generate (pubkey&pub, privkey&priv, prng&rng, uint m, uint t) matrix generator; for (;;) if (priv.h.create_goppa_generator - (generator, priv.hperm, rng) ) break; + (generator, priv.hperm, rng)) break; //scramble matrix matrix S; @@ -72,8 +72,8 @@ int pubkey::encrypt (const bvector& in, bvector&out, prng&rng) int pubkey::encrypt (const bvector&in, bvector&out, const bvector&errors) { - if (in.size() != plain_size() ) return 2; - if (errors.size() != cipher_size() ) return 2; + if (in.size() != plain_size()) return 2; + if (errors.size() != cipher_size()) return 2; G.mult_vecT_left (in, out); out.add (errors); return 0; @@ -87,7 +87,7 @@ int privkey::decrypt (const bvector&in, bvector&out) int privkey::decrypt (const bvector&in, bvector&out, bvector&errors) { - if (in.size() != cipher_size() ) return 2; + if (in.size() != cipher_size()) return 2; //remove the P permutation bvector not_permuted; @@ -104,7 +104,7 @@ int privkey::decrypt (const bvector&in, bvector&out, bvector&errors) compute_goppa_error_locator (synd, fld, g, sqInv, loc); bvector ev; - if (!evaluate_error_locator_trace (loc, ev, fld) ) + if (!evaluate_error_locator_trace (loc, ev, fld)) return 1; //if decoding somehow failed, fail as well. //correct the errors @@ -115,7 +115,7 @@ int privkey::decrypt (const bvector&in, bvector&out, bvector&errors) hperm.permute (ev, errors); //get rid of redundancy bits - not_permuted.resize (plain_size() ); + not_permuted.resize (plain_size()); //unscramble the result Sinv.mult_vecT_left (not_permuted, out); @@ -166,14 +166,14 @@ int privkey::sign (const bvector&in, bvector&out, uint delta, uint attempts, prn synd.to_poly (Synd, fld); compute_goppa_error_locator (Synd, fld, g, sqInv, loc); - if (evaluate_error_locator_trace (loc, e2, fld) ) { + if (evaluate_error_locator_trace (loc, e2, fld)) { //recreate the decodable codeword p.add (e); p.add (e2); hperm.permute (p, e2); //back to systematic - e2.resize (signature_size() ); //strip to message + e2.resize (signature_size()); //strip to message Sinv.mult_vecT_left (e2, out); //signature return 0; } @@ -191,9 +191,9 @@ int privkey::sign (const bvector&in, bvector&out, uint delta, uint attempts, prn int pubkey::verify (const bvector&in, const bvector&hash, uint delta) { bvector tmp; - if (!G.mult_vecT_left (in, tmp) ) return 2; //wrong size of input - if (hash.size() != tmp.size() ) return 1; //wrong size of hash, not a sig. + if (!G.mult_vecT_left (in, tmp)) return 2; //wrong size of input + if (hash.size() != tmp.size()) return 1; //wrong size of hash, not a sig. tmp.add (hash); - if (tmp.hamming_weight() > (t + delta) ) return 1; //not a signature + if (tmp.hamming_weight() > (t + delta)) return 1; //not a signature return 0; //sig OK } diff --git a/src/message.cpp b/src/message.cpp index 6740891..a18579a 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -27,9 +27,9 @@ int encrypted_msg::encrypt (const bvector&msg, alg_id = Alg_id; algorithm*alg = NULL; - if (algs.count (alg_id) ) { + if (algs.count (alg_id)) { alg = algs[alg_id]; - if (!alg->provides_encryption() ) + if (!alg->provides_encryption()) alg = NULL; } @@ -46,9 +46,9 @@ int encrypted_msg::encrypt (const bvector&msg, int encrypted_msg::decrypt (bvector& msg, algorithm_suite&algs, keyring& kr) { algorithm*alg = NULL; - if (algs.count (alg_id) ) { + if (algs.count (alg_id)) { alg = algs[alg_id]; - if (!alg->provides_encryption() ) + if (!alg->provides_encryption()) alg = NULL; } @@ -72,9 +72,9 @@ int signed_msg::sign (const bvector&msg, message = msg; algorithm*alg = NULL; - if (algs.count (alg_id) ) { + if (algs.count (alg_id)) { alg = algs[alg_id]; - if (!alg->provides_signatures() ) + if (!alg->provides_signatures()) alg = NULL; } @@ -94,7 +94,7 @@ int signed_msg::sign (const bvector&msg, if (privkey_dirty) { //we can't output a signature without storing privkey changes! - if (!kr.save() ) return 4; + if (!kr.save()) return 4; } return 0; @@ -103,9 +103,9 @@ int signed_msg::sign (const bvector&msg, int signed_msg::verify (algorithm_suite&algs, keyring&kr) { algorithm*alg = NULL; - if (algs.count (alg_id) ) { + if (algs.count (alg_id)) { alg = algs[alg_id]; - if (!alg->provides_signatures() ) + if (!alg->provides_signatures()) alg = NULL; } diff --git a/src/nd.cpp b/src/nd.cpp index 2a65004..fd0d234 100644 --- a/src/nd.cpp +++ b/src/nd.cpp @@ -61,14 +61,14 @@ int privkey::prepare () int pubkey::encrypt (const bvector& in, bvector&out) { - if (in.size() != plain_size() ) return 1; + if (in.size() != plain_size()) return 1; H.mult_vec_right (in, out); return 0; } int privkey::decrypt (const bvector&in, bvector&out) { - if (in.size() != cipher_size() ) return 2; + if (in.size() != cipher_size()) return 2; bvector unsc; //unscrambled Sinv.mult_vec_right (in, unsc); @@ -78,10 +78,10 @@ int privkey::decrypt (const bvector&in, bvector&out) compute_goppa_error_locator (synd, fld, g, sqInv, loc); bvector ev; - if (!evaluate_error_locator_trace (loc, ev, fld) ) + if (!evaluate_error_locator_trace (loc, ev, fld)) return 1; - if ( (int) ev.hamming_weight() != g.degree() ) + if ( (int) ev.hamming_weight() != g.degree()) return 1; Pinv.permute (ev, out); @@ -111,7 +111,7 @@ int privkey::sign (const bvector&in, bvector&out, uint delta, uint attempts, prn synd_unsc.to_poly (Synd, fld); compute_goppa_error_locator (Synd, fld, g, sqInv, loc); - if (evaluate_error_locator_trace (loc, e, fld) ) { + if (evaluate_error_locator_trace (loc, e, fld)) { Pinv.permute (e, out); return 0; @@ -124,8 +124,8 @@ int privkey::sign (const bvector&in, bvector&out, uint delta, uint attempts, prn int pubkey::verify (const bvector&in, const bvector&hash, uint delta) { bvector tmp; - if (!H.mult_vec_right (in, tmp) ) return 2; - if (hash.size() != tmp.size() ) return 1; + if (!H.mult_vec_right (in, tmp)) return 2; + if (hash.size() != tmp.size()) return 1; tmp.add (hash); if (tmp.hamming_weight() > delta) return 1; return 0; diff --git a/src/permutation.cpp b/src/permutation.cpp index 9f4d4ca..d2905ba 100644 --- a/src/permutation.cpp +++ b/src/permutation.cpp @@ -46,7 +46,7 @@ void permutation::generate_random (uint size, prng&rng) void permutation::permute_rows (const matrix&a, matrix&r) const { - r.resize (a.size() ); + r.resize (a.size()); for (uint i = 0; i < a.size(); ++i) permute (a[i], r[i]); } diff --git a/src/permutation.h b/src/permutation.h index 2908871..c8bce91 100644 --- a/src/permutation.h +++ b/src/permutation.h @@ -45,12 +45,12 @@ public: } template void permute (const A&a, R&r) const { - r.resize (a.size() ); + r.resize (a.size()); for (uint i = 0; i < size(); ++i) r[item (i) ] = a[i]; } template void permute_inv (const A&a, R&r) const { - r.resize (a.size() ); + r.resize (a.size()); for (uint i = 0; i < size(); ++i) r[i] = a[item (i)]; } @@ -67,9 +67,9 @@ public: s >>= 1; } - if (sig >= a.size() ) return false; + if (sig >= a.size()) return false; - r.resize (a.size() ); + r.resize (a.size()); uint i, t, x; for (i = 0; i < a.size(); ++i) { @@ -78,7 +78,7 @@ public: //flip the correct bit in signature t = i + 1; x = 1; - while (! (t & 1) ) { + while (! (t & 1)) { t >>= 1; x <<= 1; } diff --git a/src/polynomial.cpp b/src/polynomial.cpp index dedf38c..d6f64f9 100644 --- a/src/polynomial.cpp +++ b/src/polynomial.cpp @@ -24,7 +24,7 @@ int polynomial::degree() const { int r; - for (r = ( (int) size() ) - 1; r >= 0; --r) if (item (r) ) break; + for (r = ( (int) size()) - 1; r >= 0; --r) if (item (r)) break; return r; } @@ -35,7 +35,7 @@ void polynomial::strip() bool polynomial::zero() const { - for (uint i = 0; i < size(); ++i) if (item (i) ) return false; + for (uint i = 0; i < size(); ++i) if (item (i)) return false; return true; } @@ -48,16 +48,16 @@ bool polynomial::one() const void polynomial::add (const polynomial&f, gf2m&fld) { int df = f.degree(); - if (df > degree() ) resize (df + 1); + if (df > degree()) resize (df + 1); for (int i = 0; i <= df; ++i) item (i) = fld.add (item (i), f[i]); } void polynomial::add_mult (const polynomial&f, uint mult, gf2m&fld) { int df = f.degree(); - if (df > degree() ) resize (df + 1); + if (df > degree()) resize (df + 1); for (int i = 0; i <= df; ++i) - item (i) = fld.add (item (i), fld.mult (mult, f[i]) ); + item (i) = fld.add (item (i), fld.mult (mult, f[i])); } void polynomial::mod (const polynomial&f, gf2m&fld) @@ -71,13 +71,13 @@ void polynomial::mod (const polynomial&f, gf2m&fld) uint hi = fld.inv (f[df]); // while there's place to substract, reduce by x^(d-df)-multiply of f for (d = degree(); d >= df; --d) - if (item (d) ) { + if (item (d)) { uint t = fld.mult (item (d), hi); for (int i = 0; i <= df; ++i) item (i + d - df) = fld.add (item (i + d - df), - fld.mult (t, f[i]) ); + fld.mult (t, f[i])); } strip(); } @@ -90,14 +90,14 @@ void polynomial::mult (const polynomial&b, gf2m&fld) db = b.degree(); clear(); - if ( (da < 0) || (db < 0) ) //multiply by zero, not much to do. + if ( (da < 0) || (db < 0)) //multiply by zero, not much to do. return; resize (da + db + 1, 0); for (i = 0; i <= da; ++i) if (a[i]) for (j = 0; j <= db; ++j) item (i + j) = fld.add (item (i + j), - fld.mult (a[i], b[j]) ); + fld.mult (a[i], b[j])); } polynomial polynomial::gcd (polynomial b, gf2m&fld) @@ -107,9 +107,9 @@ polynomial polynomial::gcd (polynomial b, gf2m&fld) //eukleides if (a.degree() < 0) return b; for (;;) { - if (b.zero() ) return a; + if (b.zero()) return a; a.mod (b, fld); - if (a.zero() ) return b; + if (a.zero()) return b; b.mod (a, fld); } //unreachable @@ -152,8 +152,8 @@ void polynomial::generate_random_irreducible (uint s, gf2m&fld, prng& rng) resize (s + 1); item (s) = 1; //degree s for (uint i = 0; i < s; ++i) item (i) = rng.random (fld.n); - while (!is_irreducible (fld) ) - item (rng.random (s) ) = rng.random (fld.n); + while (!is_irreducible (fld)) + item (rng.random (s)) = rng.random (fld.n); } bool polynomial::compute_square_root_matrix (std::vector&r, @@ -234,7 +234,7 @@ uint polynomial::eval (uint x, gf2m&fld) const uint r = 0; //horner for (int i = degree(); i >= 0; --i) - r = fld.add (item (i), fld.mult (r, x) ); + r = fld.add (item (i), fld.mult (r, x)); return r; } @@ -259,7 +259,7 @@ void polynomial::make_monic (gf2m&fld) { int d = degree(); if (d < 0) return; - uint m = fld.inv (item (d) ); + uint m = fld.inv (item (d)); for (int i = 0; i <= d; ++i) item (i) = fld.mult (item (i), m); } @@ -284,14 +284,14 @@ void polynomial::sqrt (std::vector& sqInv, gf2m&fld) for (uint i = 0; i < s; ++i) { for (uint j = 0; j < s; ++j) { - if (j >= a.size() ) break; - if (i >= sqInv[j].size() ) continue; - item (i) = fld.add (item (i), fld.mult (sqInv[j][i], a[j]) ); + if (j >= a.size()) break; + if (i >= sqInv[j].size()) continue; + item (i) = fld.add (item (i), fld.mult (sqInv[j][i], a[j])); } } strip(); for (uint i = 0; i < size(); ++i) - item (i) = fld.sq_root (item (i) ); + item (i) = fld.sq_root (item (i)); } void polynomial::div (polynomial&p, polynomial&m, gf2m&fld) @@ -339,12 +339,12 @@ void polynomial::divmod (polynomial&d, polynomial&res, polynomial&rem, gf2m&fld) rem = *this; res.clear(); int t; - while ( (t = rem.degree() ) >= degd) { + while ( (t = rem.degree()) >= degd) { int rp = t - degd; if ( (int) res.size() < rp + 1) res.resize (rp + 1, 0); res[rp] = fld.mult (headInv, rem[t]); for (int i = 0; i <= degd; ++i) - rem[i + rp] = fld.add (rem[i + rp], fld.mult (res[rp], d[i]) ); + rem[i + rp] = fld.add (rem[i + rp], fld.mult (res[rp], d[i])); } rem.strip(); } @@ -377,8 +377,8 @@ void polynomial::ext_euclid (polynomial&a_out, polynomial&b_out, A.swap (a); B.swap (b); - while ( (j = A.degree() - a.degree() ) >= 0) { - h = fld.div (A.head(), a.head() ); + while ( (j = A.degree() - a.degree()) >= 0) { + h = fld.div (A.head(), a.head()); tmp = a; tmp.shift (j); A.add_mult (tmp, h, fld); diff --git a/src/polynomial.h b/src/polynomial.h index 8471996..e7ceb85 100644 --- a/src/polynomial.h +++ b/src/polynomial.h @@ -45,7 +45,7 @@ public: uint eval (uint, gf2m&) const; uint head() { int t; - if ( (t = degree() ) >= 0) return item (t); + if ( (t = degree()) >= 0) return item (t); else return 0; } void add (const polynomial&, gf2m&); diff --git a/src/qd_utils.cpp b/src/qd_utils.cpp index 7fdb4b4..30869ef 100644 --- a/src/qd_utils.cpp +++ b/src/qd_utils.cpp @@ -133,7 +133,7 @@ bool qd_to_right_echelon_form (std::vector >&mat) l = mat [w - h + i] [j].hamming_weight(); if (l == 0) continue; //zero is just okay :] - if (! (l % 2) ) //singular, make it regular by adding the i-th row + if (! (l % 2)) //singular, make it regular by adding the i-th row for (k = 0; k < w; ++k) @@ -178,7 +178,7 @@ bool qd_to_right_echelon_form (std::vector >&mat) l = mat[w - i - 1] [h - j - 1].hamming_weight(); if (l == 0) continue; //already zero - if (! (l % 2) ) { //nonsingular, fix it by adding diagonal + if (! (l % 2)) { //nonsingular, fix it by adding diagonal for (k = 0; k < w; ++k) mat[k][h - j - 1].add (mat[k][h - i - 1]); @@ -206,7 +206,7 @@ uint choose_random (uint limit, prng&rng, std::set&used) if (used.size() >= limit - 1) return 0; //die for (;;) { uint a = 1 + rng.random (limit - 1); - if (used.count (a) ) continue; + if (used.count (a)) continue; used.insert (a); return a; } diff --git a/src/sc.cpp b/src/sc.cpp index 25ab89c..95c1334 100644 --- a/src/sc.cpp +++ b/src/sc.cpp @@ -33,7 +33,7 @@ streamcipher::suite_t& streamcipher::suite() static factoryof type##_var; \ s[to_unicase(name)]=&type##_var; - if (s.empty() ) { + if (s.empty()) { do_cipher ("ARCFOUR", arcfour_t); do_cipher ("CHACHA20", chacha20); do_cipher ("XSYND", xsynd); diff --git a/src/sc.h b/src/sc.h index 148e3a5..f206b9e 100644 --- a/src/sc.h +++ b/src/sc.h @@ -48,7 +48,7 @@ public: } void load_key_vector (const std::vector&K) { - load_key (& (K[0]), & (K[K.size()]) ); + load_key (& (K[0]), & (K[K.size()])); } typedef std::map*> suite_t; diff --git a/src/sencode.cpp b/src/sencode.cpp index e25049d..218ed3f 100644 --- a/src/sencode.cpp +++ b/src/sencode.cpp @@ -53,7 +53,7 @@ static void parse_int (const std::string&str, int&pos, int len, for (;;) { if (pos >= len) goto fail; //not terminated else if (str[pos] == 'e') break; //done good - else if ( (str[pos] >= '0') and (str[pos] <= '9') ) //integer + else if ( (str[pos] >= '0') and (str[pos] <= '9')) //integer res = (10 * res) + (unsigned int) (str[pos] - '0'); else goto fail; //something weird! ++pos; @@ -93,7 +93,7 @@ static void parse_string (const std::string&str, int&pos, int len, for (;;) { if (pos >= len) goto fail; else if (str[pos] == ':') break; //got it - else if ( (str[pos] >= '0') and (str[pos] <= '9') ) //integer + else if ( (str[pos] >= '0') and (str[pos] <= '9')) //integer bytes = (10 * bytes) + (int) (str[pos] - '0'); else goto fail; //weird! ++pos; @@ -132,18 +132,18 @@ sencode* sencode_decode (const std::string& str) unsigned int res; parse_int (str, pos, len, res); if (pos < 0) break; - stk.push_back (new sencode_int (res) ); + stk.push_back (new sencode_int (res)); - } else if ( (str[pos] >= '0') && (str[pos] <= '9') ) { + } else if ( (str[pos] >= '0') && (str[pos] <= '9')) { //parse a bytestring std::string res; parse_string (str, pos, len, res); if (pos < 0) break; - stk.push_back (new sencode_bytes (res) ); + stk.push_back (new sencode_bytes (res)); } /* if there's nothing on the stack now, it's an error. */ - if (stk.empty() ) break; + if (stk.empty()) break; /* reduce stack. (return positively if it would * get empty and there's nothing more to parse.) */ diff --git a/src/sencode.h b/src/sencode.h index 2d46eb2..2bdb7ad 100644 --- a/src/sencode.h +++ b/src/sencode.h @@ -65,7 +65,7 @@ class sencode_bytes: public sencode public: std::string b; sencode_bytes (const std::string&s) : b (s) {} - sencode_bytes (const std::vector&a) : b (a.begin(), a.end() ) {} + sencode_bytes (const std::vector&a) : b (a.begin(), a.end()) {} virtual std::string encode(); }; diff --git a/src/serialization.cpp b/src/serialization.cpp index 135f3c9..9d0850c 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -42,7 +42,7 @@ static sencode* serialize_uint_vector (std::vector*v) { sencode_list*l = new sencode_list; - l->items.resize (v->size() ); + l->items.resize (v->size()); for (uint i = 0; i < v->size(); ++i) l->items[i] = new sencode_int ( (*v) [i]); return l; @@ -53,7 +53,7 @@ static bool unserialize_uint_vector (std::vector*v, sencode*s) sencode_list* CAST_LIST (s, l); v->clear(); - v->resize (l->items.size() ); + v->resize (l->items.size()); for (uint i = 0; i < v->size(); ++i) { sencode_int*CAST_INT (l->items[i], x); (*v) [i] = x->i; @@ -67,10 +67,10 @@ sencode* bvector::serialize() std::string bytes; bytes.resize (ss, '\0'); for (uint i = 0; i < size(); ++i) - if (item (i) ) bytes[i / 8] |= 1 << (i % 8); + if (item (i)) bytes[i / 8] |= 1 << (i % 8); sencode_list*l = new sencode_list; - l->items.push_back (new sencode_int (size() ) ); - l->items.push_back (new sencode_bytes (bytes) ); + l->items.push_back (new sencode_int (size())); + l->items.push_back (new sencode_bytes (bytes)); return l; } @@ -81,11 +81,11 @@ bool bvector::unserialize (sencode* s) if (l->items.size() != 2) return false; sencode_int*CAST_INT (l->items[0], size); sencode_bytes*CAST_BYTES (l->items[1], bytes); - if (bytes->b.size() != ( (size->i + 7) / 8) ) return false; + if (bytes->b.size() != ( (size->i + 7) / 8)) return false; clear(); resize (size->i, 0); for (i = 0; i < size->i; ++i) - if ( (bytes->b[i / 8] >> (i % 8) ) & 1) + if ( (bytes->b[i / 8] >> (i % 8)) & 1) item (i) = 1; /* @@ -93,7 +93,7 @@ bool bvector::unserialize (sencode* s) * sencode serialization must be bijective */ for (; i < 8 * bytes->b.size(); ++i) - if ( (bytes->b[i / 8] >> (i % 8) ) & 1) + if ( (bytes->b[i / 8] >> (i % 8)) & 1) return false; return true; @@ -106,11 +106,11 @@ sencode* matrix::serialize() std::string bytes; bytes.resize (ss, '\0'); for (uint i = 0; i < bits; ++i) - if (item (i / height(), i % height() ) ) bytes[i / 8] |= 1 << (i % 8); + if (item (i / height(), i % height())) bytes[i / 8] |= 1 << (i % 8); sencode_list*l = new sencode_list; - l->items.push_back (new sencode_int (width() ) ); - l->items.push_back (new sencode_int (height() ) ); - l->items.push_back (new sencode_bytes (bytes) ); + l->items.push_back (new sencode_int (width())); + l->items.push_back (new sencode_int (height())); + l->items.push_back (new sencode_bytes (bytes)); return l; } @@ -121,11 +121,11 @@ bool matrix::unserialize (sencode* s) sencode_int*CAST_INT (l->items[0], w); sencode_int*CAST_INT (l->items[1], h); sencode_bytes*CAST_BYTES (l->items[2], bytes); - if (bytes->b.size() != ( ( (h->i * w->i) + 7) / 8) ) return false; + if (bytes->b.size() != ( ( (h->i * w->i) + 7) / 8)) return false; clear(); resize2 (w->i, h->i, 0); for (uint i = 0; i < w->i * h->i; ++i) - if ( (bytes->b[i / 8] >> (i % 8) ) & 1) + if ( (bytes->b[i / 8] >> (i % 8)) & 1) item (i / h->i, i % h->i) = 1; return true; } @@ -137,10 +137,10 @@ sencode* permutation::serialize() bool permutation::unserialize (sencode* s) { - if (!unserialize_uint_vector (this, s) ) return false; + if (!unserialize_uint_vector (this, s)) return false; //small sanity check - for (uint i = 0; i < size(); ++i) if (item (i) >= size() ) return false; + for (uint i = 0; i < size(); ++i) if (item (i) >= size()) return false; return true; } @@ -188,13 +188,13 @@ bool mce::privkey::unserialize (sencode* s) if (l->items.size() != 6) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PRIVKEY_IDENT "MCE") ) return false; + if (ident->b.compare (PRIVKEY_IDENT "MCE")) return false; if (! (fld.unserialize (l->items[1]) && g.unserialize (l->items[2]) && hperm.unserialize (l->items[3]) && Pinv.unserialize (l->items[4]) && - Sinv.unserialize (l->items[5]) ) ) return false; + Sinv.unserialize (l->items[5]))) return false; return true; } @@ -215,12 +215,12 @@ bool mce::pubkey::unserialize (sencode* s) if (l->items.size() != 3) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PUBKEY_IDENT "MCE") ) return false; + if (ident->b.compare (PUBKEY_IDENT "MCE")) return false; sencode_int*CAST_INT (l->items[0], p); t = p->i; - if (!G.unserialize (l->items[1]) ) return false; + if (!G.unserialize (l->items[1])) return false; return true; } @@ -243,12 +243,12 @@ bool nd::privkey::unserialize (sencode* s) if (l->items.size() != 5) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PRIVKEY_IDENT "ND") ) return false; + if (ident->b.compare (PRIVKEY_IDENT "ND")) return false; if (! (fld.unserialize (l->items[1]) && g.unserialize (l->items[2]) && Pinv.unserialize (l->items[3]) && - Sinv.unserialize (l->items[4]) ) ) return false; + Sinv.unserialize (l->items[4]))) return false; return true; } @@ -269,12 +269,12 @@ bool nd::pubkey::unserialize (sencode* s) if (l->items.size() != 3) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PRIVKEY_IDENT "ND") ) return false; + if (ident->b.compare (PRIVKEY_IDENT "ND")) return false; sencode_int*CAST_INT (l->items[1], p); t = p->i; - if (!H.unserialize (l->items[2]) ) return false; + if (!H.unserialize (l->items[2])) return false; return true; } @@ -299,7 +299,7 @@ bool mce_qd::privkey::unserialize (sencode* s) if (l->items.size() != 7) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PRIVKEY_IDENT "QD-MCE") ) return false; + if (ident->b.compare (PRIVKEY_IDENT "QD-MCE")) return false; sencode_int*CAST_INT (l->items[2], p); T = p->i; @@ -308,7 +308,7 @@ bool mce_qd::privkey::unserialize (sencode* s) unserialize_uint_vector (&essence, l->items[3]) && block_perm.unserialize (l->items[4]) && unserialize_uint_vector (&block_perms, l->items[5]) && - hperm.unserialize (l->items[6]) ) ) return false; + hperm.unserialize (l->items[6]))) return false; return true; } @@ -329,12 +329,12 @@ bool mce_qd::pubkey::unserialize (sencode* s) if (l->items.size() != 3) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PUBKEY_IDENT "QD-MCE") ) return false; + if (ident->b.compare (PUBKEY_IDENT "QD-MCE")) return false; sencode_int*CAST_INT (l->items[1], p); T = p->i; - if (!qd_sigs.unserialize (l->items[2]) ) return false; + if (!qd_sigs.unserialize (l->items[2])) return false; return true; } @@ -362,7 +362,7 @@ bool fmtseq::privkey::tree_stk_item::unserialize (sencode*s) pos = p->i; sencode_bytes* CAST_BYTES (l->items[2], a); - item = std::vector (a->b.begin(), a->b.end() ); + item = std::vector (a->b.begin(), a->b.end()); return true; @@ -403,34 +403,34 @@ sencode* fmtseq::privkey::serialize() L->items[8] = S = new sencode_list; L->items[9] = P = new sencode_list; - E->items.resize (exist.size() ); + E->items.resize (exist.size()); for (i = 0; i < exist.size(); ++i) { sencode_list *t = new sencode_list; E->items[i] = t; - t->items.resize (exist[i].size() ); + t->items.resize (exist[i].size()); for (j = 0; j < exist[i].size(); ++j) t->items[j] = new sencode_bytes (exist[i][j]); } - D->items.resize (desired.size() ); + D->items.resize (desired.size()); for (i = 0; i < desired.size(); ++i) { sencode_list *t = new sencode_list; D->items[i] = t; - t->items.resize (desired[i].size() ); + t->items.resize (desired[i].size()); for (j = 0; j < desired[i].size(); ++j) t->items[j] = new sencode_bytes (desired[i][j]); } - S->items.resize (desired_stack.size() ); + S->items.resize (desired_stack.size()); for (i = 0; i < desired_stack.size(); ++i) { sencode_list *t = new sencode_list; S->items[i] = t; - t->items.resize (desired_stack[i].size() ); + t->items.resize (desired_stack[i].size()); for (j = 0; j < desired_stack[i].size(); ++j) t->items[j] = desired_stack[i][j].serialize(); } - P->items.resize (desired_progress.size() ); + P->items.resize (desired_progress.size()); for (i = 0; i < desired_progress.size(); ++i) P->items[i] = new sencode_int (desired_progress[i]); @@ -444,13 +444,13 @@ bool fmtseq::privkey::unserialize (sencode*s) if (L->items.size() != 10) return false; sencode_bytes*CAST_BYTES (L->items[0], ident); - if (ident->b.compare (PRIVKEY_IDENT "FMTSEQ") ) return false; + if (ident->b.compare (PRIVKEY_IDENT "FMTSEQ")) return false; sencode_bytes*B; sencode_int*I; CAST_BYTES (L->items[1], B); - SK = std::vector (B->b.begin(), B->b.end() ); + SK = std::vector (B->b.begin(), B->b.end()); CAST_INT (L->items[2], I); h = I->i; @@ -469,49 +469,49 @@ bool fmtseq::privkey::unserialize (sencode*s) //exist subtrees CAST_LIST (L->items[6], A); exist.clear(); - exist.resize (A->items.size() ); + exist.resize (A->items.size()); for (i = 0; i < exist.size(); ++i) { sencode_list*CAST_LIST (A->items[i], e); - exist[i].resize (e->items.size() ); + exist[i].resize (e->items.size()); for (j = 0; j < exist[i].size(); ++j) { sencode_bytes*CAST_BYTES (e->items[j], item); exist[i][j] = std::vector (item->b.begin(), - item->b.end() ); + item->b.end()); } } //desired subtrees CAST_LIST (L->items[7], A); desired.clear(); - desired.resize (A->items.size() ); + desired.resize (A->items.size()); for (i = 0; i < desired.size(); ++i) { sencode_list*CAST_LIST (A->items[i], d); - desired[i].resize (d->items.size() ); + desired[i].resize (d->items.size()); for (j = 0; j < desired[i].size(); ++j) { sencode_bytes*CAST_BYTES (d->items[j], item); desired[i][j] = std::vector (item->b.begin(), - item->b.end() ); + item->b.end()); } } //desired stacks CAST_LIST (L->items[8], A); desired_stack.clear(); - desired_stack.resize (A->items.size() ); + desired_stack.resize (A->items.size()); for (i = 0; i < desired_stack.size(); ++i) { sencode_list*CAST_LIST (A->items[i], d); - desired_stack[i].resize (d->items.size() ); + desired_stack[i].resize (d->items.size()); for (j = 0; j < desired_stack[i].size(); ++j) - if (!desired_stack[i][j].unserialize (d->items[j]) ) + if (!desired_stack[i][j].unserialize (d->items[j])) return false; } //desired progress CAST_LIST (L->items[9], A); desired_progress.clear(); - desired_progress.resize (A->items.size() ); + desired_progress.resize (A->items.size()); for (i = 0; i < desired_progress.size(); ++i) { CAST_INT (A->items[i], I); desired_progress[i] = I->i; @@ -539,7 +539,7 @@ bool fmtseq::pubkey::unserialize (sencode*s) if (l->items.size() != 4) return false; sencode_bytes*CAST_BYTES (l->items[0], ident); - if (ident->b.compare (PUBKEY_IDENT "FMTSEQ") ) return false; + if (ident->b.compare (PUBKEY_IDENT "FMTSEQ")) return false; sencode_int*p; CAST_INT (l->items[1], p); @@ -549,7 +549,7 @@ bool fmtseq::pubkey::unserialize (sencode*s) hs = p->i; sencode_bytes* CAST_BYTES (l->items[3], a); - check = std::vector (a->b.begin(), a->b.end() ); + check = std::vector (a->b.begin(), a->b.end()); return true; } @@ -634,7 +634,7 @@ bool signed_msg::unserialize (sencode*s) sencode* hashfile::serialize() { sencode_list*L = new sencode_list(); - L->items.resize (1 + hashes.size() ); + L->items.resize (1 + hashes.size()); L->items[0] = new sencode_bytes (HASHFILE_IDENT); uint pos = 1; for (hashes_t::iterator i = hashes.begin(), e = hashes.end(); i != e; ++i, ++pos) { @@ -666,9 +666,9 @@ bool hashfile::unserialize (sencode*s) sencode_bytes*CAST_BYTES (hash->items[1], value); //prevent multiple hash entries of same hash - if (hashes.count (name->b) ) return false; + if (hashes.count (name->b)) return false; - hashes[name->b] = std::vector (value->b.begin(), value->b.end() ); + hashes[name->b] = std::vector (value->b.begin(), value->b.end()); } return true; @@ -699,7 +699,7 @@ sencode* symkey::serialize() std::set::iterator i, e; LL = new sencode_list(); - LL->items.resize (ciphers.size() ); + LL->items.resize (ciphers.size()); k = 0; for (i = ciphers.begin(), e = ciphers.end(); i != e; ++i) @@ -707,7 +707,7 @@ sencode* symkey::serialize() L->items[1] = LL; LL = new sencode_list(); - LL->items.resize (hashes.size() ); + LL->items.resize (hashes.size()); k = 0; for (i = hashes.begin(), e = hashes.end(); i != e; ++i) @@ -734,7 +734,7 @@ bool symkey::unserialize (sencode*s) CAST_BYTES (L->items[4], B); key.clear(); - key.insert (key.begin(), B->b.begin(), B->b.end() ); + key.insert (key.begin(), B->b.begin(), B->b.end()); sencode_list*LL; uint i; @@ -743,7 +743,7 @@ bool symkey::unserialize (sencode*s) ciphers.clear(); for (i = 0; i < LL->items.size(); ++i) { CAST_BYTES (LL->items[i], B); - if (ciphers.count (B->b) ) return false; + if (ciphers.count (B->b)) return false; ciphers.insert (B->b); } @@ -751,7 +751,7 @@ bool symkey::unserialize (sencode*s) hashes.clear(); for (i = 0; i < LL->items.size(); ++i) { CAST_BYTES (LL->items[i], B); - if (hashes.count (B->b) ) return false; + if (hashes.count (B->b)) return false; hashes.insert (B->b); } diff --git a/src/sha_hash.h b/src/sha_hash.h index b11b44f..93a7772 100644 --- a/src/sha_hash.h +++ b/src/sha_hash.h @@ -35,10 +35,10 @@ public: std::vector operator() (const std::vector&a) { std::vector r; - r.resize (size() ); + r.resize (size()); shatype().CalculateDigest (& (r[0]), & (a[0]), - a.size() ); + a.size()); return r; } }; @@ -66,8 +66,8 @@ public: std::vector finish() { std::vector r; - r.resize (size() ); - state.Final (& (r[0]) ); + r.resize (size()); + state.Final (& (r[0])); return r; } }; diff --git a/src/str_match.cpp b/src/str_match.cpp index d4ca38e..f10aa5b 100644 --- a/src/str_match.cpp +++ b/src/str_match.cpp @@ -26,9 +26,9 @@ bool algorithm_name_matches (const std::string& search, const std::string&name) { - if (search.length() > name.length() ) return false; + if (search.length() > name.length()) return false; for (size_t i = 0; i < search.length(); ++i) - if (tolower (search[i]) != tolower (name[i]) ) return false; + if (tolower (search[i]) != tolower (name[i])) return false; return true; } @@ -43,11 +43,11 @@ bool keyspec_matches (const std::string&search, const std::string&name, const std::string&keyid) { - if (!search.length() ) return true; + if (!search.length()) return true; if (search[0] == '@') { //match for keyID if (search.length() > keyid.length() + 1) return false; for (size_t i = 1; i < search.length(); ++i) - if (tolower (search[i] != tolower (keyid[i - 1]) ) ) + if (tolower (search[i] != tolower (keyid[i - 1]))) return false; return true; } diff --git a/src/symkey.cpp b/src/symkey.cpp index df62244..0d7d893 100644 --- a/src/symkey.cpp +++ b/src/symkey.cpp @@ -42,14 +42,14 @@ bool symkey::create (const std::string&in, prng&rng) uint keysize = 32; std::stringstream ss (in); std::string tok; - while (getline (ss, tok, ',') ) { + while (getline (ss, tok, ',')) { tok = to_unicase (tok); if (tok == "SHORTBLOCK") blocksize = 1024; else if (tok == "LONGBLOCK") blocksize = 64 * 1024 * 1024; else if (tok == "LONGKEY") keysize = 512; //overkill ;] - else if (streamcipher::suite().count (tok) ) + else if (streamcipher::suite().count (tok)) ciphers.insert (tok); - else if (hash_proc::suite().count (tok) ) + else if (hash_proc::suite().count (tok)) hashes.insert (tok); else { err ("symkey: unknown token: " << tok); @@ -63,7 +63,7 @@ bool symkey::create (const std::string&in, prng&rng) i != e; ++i) { instanceof sc - (streamcipher::suite() [*i]->get() ); + (streamcipher::suite() [*i]->get()); sc.collect(); if (sc->key_size() > keysize) keysize = sc->key_size(); } @@ -73,7 +73,7 @@ bool symkey::create (const std::string&in, prng&rng) key.resize (keysize); for (uint i = 0; i < keysize; ++i) key[i] = rng.random (256); - if (!is_valid() ) { + if (!is_valid()) { err ("symkey: failed to produce valid symmetric key"); err ("symkey: check that at least one hash and cipher is used"); return false; @@ -87,7 +87,7 @@ typedef std::list > hashes_t; bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) { - if (!is_valid() ) return false; + if (!is_valid()) return false; /* * structure of symmetrically encrypted file: @@ -103,7 +103,7 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) */ std::vector otkey; - otkey.resize (key.size() ); + otkey.resize (key.size()); for (uint i = 0; i < otkey.size(); ++i) otkey[i] = rng.random (256); /* @@ -114,11 +114,11 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) for (std::set::iterator i = ciphers.begin(), e = ciphers.end(); i != e; ++i) { - if (!streamcipher::suite().count (*i) ) { + if (!streamcipher::suite().count (*i)) { err ("symkey: unsupported cipher: " << *i); return false; } - scs.push_back (streamcipher::suite() [*i]->get() ); + scs.push_back (streamcipher::suite() [*i]->get()); scs.back().collect(); scs.back()->init(); scs.back()->load_key_vector (key); @@ -135,11 +135,11 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) for (std::set::iterator i = hashes.begin(), e = hashes.end(); i != e; ++i) { - if (!hash_proc::suite().count (*i) ) { + if (!hash_proc::suite().count (*i)) { err ("symkey: unsupported hash function: " << *i); return false; } - hs.push_back (hash_proc::suite() [*i]->get() ); + hs.push_back (hash_proc::suite() [*i]->get()); hs.back().collect(); hashes_size += hs.back()->size(); @@ -149,7 +149,7 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) * output the onetime key */ - out.write ( (char*) & (otkey[0]), otkey.size() ); + out.write ( (char*) & (otkey[0]), otkey.size()); /* * process the blocks @@ -157,13 +157,13 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) std::vectorbuf, cipbuf; buf.resize (blocksize + hashes_size); - cipbuf.resize (buf.size() ); + cipbuf.resize (buf.size()); for (;;) { in.read ( (char*) & (buf[0]), blocksize); uint bytes_read = in.gcount(); - if (!in && !in.eof() ) { + if (!in && !in.eof()) { err ("symkey: failed reading input"); return false; } @@ -174,7 +174,7 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) i != e; ++i) { hash_proc&hp = **i; hp.init(); - hp.eat (& (buf[0]), & (buf[bytes_read]) ); + hp.eat (& (buf[0]), & (buf[bytes_read])); hp.eat (key); hp.eat (otkey); std::vector res = hp.finish(); @@ -187,7 +187,7 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) for (scs_t::iterator i = scs.begin(), e = scs.end(); i != e; ++i) { streamcipher&sc = **i; - sc.gen (hashpos, & (cipbuf[0]) ); + sc.gen (hashpos, & (cipbuf[0])); for (uint j = 0; j < hashpos; ++j) buf[j] = buf[j] ^ cipbuf[j]; } @@ -208,16 +208,16 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng) int symkey::decrypt (std::istream&in, std::ostream&out) { - if (!is_valid() ) return 1; + if (!is_valid()) return 1; std::vector otkey; - otkey.resize (key.size() ); + otkey.resize (key.size()); /* * read otkey */ - in.read ( (char*) & (otkey[0]), otkey.size() ); + in.read ( (char*) & (otkey[0]), otkey.size()); if (in.gcount() != (std::streamsize) otkey.size() || !in) { err ("symkey: failed reading input"); return 1; @@ -231,11 +231,11 @@ int symkey::decrypt (std::istream&in, std::ostream&out) for (std::set::iterator i = ciphers.begin(), e = ciphers.end(); i != e; ++i) { - if (!streamcipher::suite().count (*i) ) { + if (!streamcipher::suite().count (*i)) { err ("symkey: unsupported cipher: " << *i); return 1; } - scs.push_back (streamcipher::suite() [*i]->get() ); + scs.push_back (streamcipher::suite() [*i]->get()); scs.back().collect(); scs.back()->init(); scs.back()->load_key_vector (key); @@ -252,11 +252,11 @@ int symkey::decrypt (std::istream&in, std::ostream&out) for (std::set::iterator i = hashes.begin(), e = hashes.end(); i != e; ++i) { - if (!hash_proc::suite().count (*i) ) { + if (!hash_proc::suite().count (*i)) { err ("symkey: unsupported hash function: " << *i); return 1; } - hs.push_back (hash_proc::suite() [*i]->get() ); + hs.push_back (hash_proc::suite() [*i]->get()); hs.back().collect(); hashes_size += hs.back()->size(); @@ -268,13 +268,13 @@ int symkey::decrypt (std::istream&in, std::ostream&out) std::vector buf, cipbuf; buf.resize (blocksize + hashes_size); - cipbuf.resize (buf.size() ); + cipbuf.resize (buf.size()); for (;;) { - in.read ( (char*) & (buf[0]), buf.size() ); + in.read ( (char*) & (buf[0]), buf.size()); uint bytes_read = in.gcount(); - if ( (!in && !in.eof() ) || bytes_read < hashes_size) { + if ( (!in && !in.eof()) || bytes_read < hashes_size) { err ("symkey: failed reading input"); return 1; } @@ -283,7 +283,7 @@ int symkey::decrypt (std::istream&in, std::ostream&out) for (scs_t::iterator i = scs.begin(), e = scs.end(); i != e; ++i) { streamcipher&sc = **i; - sc.gen (bytes_read, & (cipbuf[0]) ); + sc.gen (bytes_read, & (cipbuf[0])); for (uint j = 0; j < bytes_read; ++j) buf[j] = buf[j] ^ cipbuf[j]; } @@ -296,7 +296,7 @@ int symkey::decrypt (std::istream&in, std::ostream&out) i != e; ++i) { hash_proc&hp = **i; hp.init(); - hp.eat (& (buf[0]), & (buf[bytes_read]) ); + hp.eat (& (buf[0]), & (buf[bytes_read])); hp.eat (key); hp.eat (otkey); std::vector res = hp.finish(); @@ -315,7 +315,7 @@ int symkey::decrypt (std::istream&in, std::ostream&out) } //did we read whole input? - if (!in.eof() ) { + if (!in.eof()) { err ("symkey: failed reading input"); return 1; } diff --git a/src/xsynd.cpp b/src/xsynd.cpp index 5961373..8a6a5d0 100644 --- a/src/xsynd.cpp +++ b/src/xsynd.cpp @@ -46,7 +46,7 @@ static void xsynd_multiply (const uint64_t*A, const uint64_t*X, uint64_t*Y) >> brot) | (A[qcoff + ( (j + wrot + 1) % 16)] - << (64 - brot) ) + << (64 - brot)) ); } }