~ubuntu-branches/ubuntu/oneiric/strongswan/oneiric

« back to all changes in this revision

Viewing changes to src/libcrypto/libaes/aes_xcbc_mac.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2009-04-18 20:28:51 UTC
  • mfrom: (1.1.9 upstream) (2.1.15 karmic)
  • Revision ID: james.westby@ubuntu.com-20090418202851-ep722qhmzvpxh6yj
Tags: 4.3.2-1
Urgency high because of security issue and FTBFS.
* New upstream release, fixes security bug.
* Fix padlock handling for i386 in debian/rules.
  Closes: #525652 (FTBFS on i386)
* Acknowledge NMUs by security team.
  Closes: #533837, #531612
* Add "Conflicts: strongswan (< 4.2.12-1)" to libstrongswan, 
  strongswan-starter, strongswan-ikev1, and strongswan-ikev2 to force
  update of the strongswan package on installation and avoid conflicts
  caused by package restructuring.
  Closes: #526037: strongswan-ikev2 and strongswan: error when trying to 
                   install together
  Closes: #526486: strongswan and libstrongswan: error when trying to 
                   install together
  Closes: #526487: strongswan-ikev1 and strongswan: error when trying to 
                   install together
  Closes: #526488: strongswan-starter and strongswan: error when trying to 
                   install together
* Debconf templates and debian/control reviewed by the debian-l10n-
  english team as part of the Smith review project. Closes: #528073
* Debconf translation updates:
  Closes: #525234: [INTL:ja] Update po-debconf template translation (ja.po) 
  Closes: #528323: [INTL:sv] po-debconf file for strongswan 
  Closes: #528370: [INTL:vi] Vietnamese debconf templates translation update 
  Closes: #529027: [INTL:pt] Updated Portuguese translation for debconf messages
  Closes: #529071: [INTL:fr] French debconf templates translation update 
  Closes: #529592: nb translation of debconf PO for strongSWAN 
  Closes: #529638: [INTL:ru] Russian debconf templates translation 
  Closes: #529661: Updated Czech translation of strongswan debconf messages 
  Closes: #529742: [INTL:eu] strongswan debconf basque translation 
  Closes: #530273: [INTL:fi] Finnish translation of the debconf templates
  Closes: #529063: [INTL:gl] strongswan 4.2.14-2 debconf translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef __KERNEL__
2
 
#include <linux/types.h>
3
 
#include <linux/kernel.h>
4
 
#define DEBUG(x) 
5
 
#else
6
 
#include <stdio.h>
7
 
#include <sys/types.h>
8
 
#define DEBUG(x) x
9
 
#endif
10
 
 
11
 
#include "aes.h"
12
 
#include "aes_xcbc_mac.h"
13
 
 
14
 
int AES_xcbc_mac_set_key(aes_context_mac *ctxm, const u_int8_t *key, int keylen)
15
 
{
16
 
        int ret=1;
17
 
        aes_block kn[3] = { 
18
 
                { 0x01010101, 0x01010101, 0x01010101, 0x01010101 },
19
 
                { 0x02020202, 0x02020202, 0x02020202, 0x02020202 },
20
 
                { 0x03030303, 0x03030303, 0x03030303, 0x03030303 },
21
 
        };
22
 
        aes_set_key(&ctxm->ctx_k1, key, keylen, 0);
23
 
        aes_encrypt(&ctxm->ctx_k1, (u_int8_t *) kn[0], (u_int8_t *) kn[0]);
24
 
        aes_encrypt(&ctxm->ctx_k1, (u_int8_t *) kn[1], (u_int8_t *) ctxm->k2);
25
 
        aes_encrypt(&ctxm->ctx_k1, (u_int8_t *) kn[2], (u_int8_t *) ctxm->k3);
26
 
        aes_set_key(&ctxm->ctx_k1, (u_int8_t *) kn[0], 16, 0);
27
 
        return ret;
28
 
}
29
 
static void do_pad_xor(u_int8_t *out, const u_int8_t *in, int len) {
30
 
        int pos=0;
31
 
        for (pos=1; pos <= 16; pos++, in++, out++) {
32
 
                if (pos <= len)
33
 
                        *out ^= *in;
34
 
                if (pos > len) {
35
 
                        DEBUG(printf("put 0x80 at pos=%d\n", pos));
36
 
                        *out ^= 0x80;
37
 
                        break;
38
 
                }
39
 
        }
40
 
}
41
 
static void xor_block(aes_block res, const aes_block op) {
42
 
        res[0] ^= op[0];
43
 
        res[1] ^= op[1];
44
 
        res[2] ^= op[2];
45
 
        res[3] ^= op[3];
46
 
}
47
 
int AES_xcbc_mac_hash(const aes_context_mac *ctxm, const u_int8_t * in, int ilen, u_int8_t hash[16]) {
48
 
        int ret=ilen;
49
 
        u_int32_t out[4] = { 0, 0, 0, 0 }; 
50
 
        for (; ilen > 16 ; ilen-=16) {
51
 
                xor_block(out, (const u_int32_t*) &in[0]);
52
 
                aes_encrypt(&ctxm->ctx_k1, in, (u_int8_t *)&out[0]);
53
 
                in+=16; 
54
 
        }
55
 
        do_pad_xor((u_int8_t *)&out, in, ilen);
56
 
        if (ilen==16) {
57
 
                DEBUG(printf("using k3\n"));
58
 
                xor_block(out, ctxm->k3);
59
 
        }
60
 
        else 
61
 
        {
62
 
                DEBUG(printf("using k2\n"));
63
 
                xor_block(out, ctxm->k2);
64
 
        }
65
 
        aes_encrypt(&ctxm->ctx_k1, (u_int8_t *)out, hash);
66
 
        return ret;
67