Mercurial > dropbear
annotate ofb_encrypt.c @ 154:b4c6e7f276e9 libtomcrypt
Makefile.in: don't compile things we don't need
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 20 Dec 2004 14:46:40 +0000 |
parents | d7da3b1e1540 |
children |
rev | line source |
---|---|
0
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 #include "mycrypt.h" |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 #ifdef OFB |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 int err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 _ARGCHK(pt != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 _ARGCHK(ct != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 _ARGCHK(ofb != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 return err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 /* is blocklen/padlen valid? */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 if (ofb->blocklen < 0 || ofb->blocklen > (int)sizeof(ofb->IV) || |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 ofb->padlen < 0 || ofb->padlen > (int)sizeof(ofb->IV)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 return CRYPT_INVALID_ARG; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 while (len-- > 0) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 if (ofb->padlen == ofb->blocklen) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 cipher_descriptor[ofb->cipher].ecb_encrypt(ofb->IV, ofb->IV, &ofb->key); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 ofb->padlen = 0; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 *ct++ = *pt++ ^ ofb->IV[ofb->padlen++]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 #endif |