summaryrefslogtreecommitdiff
path: root/src/cipher.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-01 18:45:05 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-01 18:45:05 +0000
commit1b6ddf7ed3a64c693b7286f8597aee6da24035d1 (patch)
tree35dd9a1fad1b4cf024560fc249760c30d75b193b /src/cipher.c
parentadded aes-ctr cipher (diff)
changed ugly salt 0 msb workaround to a mor sophisticated solution
Diffstat (limited to 'src/cipher.c')
-rw-r--r--src/cipher.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cipher.c b/src/cipher.c
index 5c23a36..ae981cd 100644
--- a/src/cipher.c
+++ b/src/cipher.c
@@ -111,8 +111,6 @@ void cipher_set_salt(cipher_t* c, u_int8_t* salt, u_int32_t len)
}
memcpy(c->salt_.buf_, salt, len);
c->salt_.length_ = len;
- if(!c->salt_.buf_[0])
- c->salt_.buf_[0] = 1; // TODO: this is a outstandingly ugly workaround
}
void cipher_close(cipher_t* c)
@@ -226,6 +224,10 @@ buffer_t cipher_aesctr_calc_ctr(cipher_t* c, seq_nr_t seq_nr, sender_id_t sender
mpz_init2(sid_mux, 96);
mpz_init2(seq, 48);
+ int faked_msb = 0;
+ if(!c->salt_.buf_[0])
+ c->salt_.buf_[0] = 1;
+
mpz_import(ctr, c->salt_.length_, 1, 1, 0, 0, c->salt_.buf_);
mpz_mul_2exp(ctr, ctr, 16);
@@ -241,6 +243,10 @@ buffer_t cipher_aesctr_calc_ctr(cipher_t* c, seq_nr_t seq_nr, sender_id_t sender
mpz_xor(ctr, ctr, seq);
result.buf_ = mpz_export(NULL, (size_t*)&result.length_, 1, 1, 0, 0, ctr);
+ if(faked_msb) {
+ c->salt_.buf_[0] = 0;
+ result.buf_[0] = 0;
+ }
mpz_clear(ctr);
mpz_clear(sid_mux);