~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to programs/pluto/ike_alg_aes.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <string.h>
 
3
#include <stddef.h>
 
4
#include <sys/types.h>
 
5
#include <openswan.h>
 
6
 
 
7
#include "constants.h"
 
8
#include "defs.h"
 
9
#include "log.h"
 
10
#include "crypto/aes_cbc.h"
 
11
#include "alg_info.h"
 
12
#include "ike_alg.h"
 
13
 
 
14
#define  AES_KEY_MIN_LEN        128
 
15
#define  AES_KEY_DEF_LEN        128
 
16
#define  AES_KEY_MAX_LEN        256
 
17
 
 
18
static void
 
19
do_aes(u_int8_t *buf, size_t buf_len, u_int8_t *key, size_t key_size, u_int8_t *iv, bool enc)
 
20
{
 
21
    aes_context aes_ctx;
 
22
    char iv_bak[AES_CBC_BLOCK_SIZE];
 
23
    char *new_iv = NULL;        /* logic will avoid copy to NULL */
 
24
 
 
25
    aes_set_key(&aes_ctx, key, key_size, 0);
 
26
 
 
27
    /*  
 
28
     *  my AES cbc does not touch passed IV (optimization for
 
29
     *  ESP handling), so I must "emulate" des-like IV
 
30
     *  crunching
 
31
     */
 
32
    if (!enc)
 
33
            memcpy(new_iv=iv_bak, 
 
34
                            (char*) buf + buf_len-AES_CBC_BLOCK_SIZE,
 
35
                            AES_CBC_BLOCK_SIZE);
 
36
 
 
37
    AES_cbc_encrypt(&aes_ctx, buf, buf, buf_len, iv, enc);
 
38
 
 
39
    if (enc)
 
40
            new_iv = (char*) buf + buf_len-AES_CBC_BLOCK_SIZE;
 
41
 
 
42
    memcpy(iv, new_iv, AES_CBC_BLOCK_SIZE);
 
43
}
 
44
 
 
45
struct encrypt_desc algo_aes =
 
46
{
 
47
        common: {algo_type:     IKE_ALG_ENCRYPT,
 
48
                 algo_id:       OAKLEY_AES_CBC,
 
49
                 algo_next:     NULL, },
 
50
        enc_ctxsize:    sizeof(aes_context),
 
51
        enc_blocksize:  AES_CBC_BLOCK_SIZE,
 
52
        keyminlen:      AES_KEY_MIN_LEN,
 
53
        keydeflen:      AES_KEY_DEF_LEN,
 
54
        keymaxlen:      AES_KEY_MAX_LEN,
 
55
        do_crypt:       do_aes,
 
56
};
 
57
int ike_alg_aes_init(void);
 
58
int
 
59
ike_alg_aes_init(void)
 
60
{
 
61
        int ret = ike_alg_register_enc(&algo_aes);
 
62
        return ret;
 
63
}
 
64
/*
 
65
IKE_ALG_INIT_NAME: ike_alg_aes_init
 
66
*/