arcfour.c 1.73 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* arcfour.c
 *
 * $Id$ */

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Mller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
J.H.M. Dassen's avatar
J.H.M. Dassen committed
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Niels Möller's avatar
Niels Möller committed
22
23
24
25
26
27
28
 */

#include "crypto.h"

#include "werror.h"
#include "xalloc.h"

Niels Möller's avatar
Niels Möller committed
29
#include "nettle/arcfour.h"
Niels Möller's avatar
Niels Möller committed
30
31
32

#include "arcfour.c.x"

33
/* GABA:
Niels Möller's avatar
Niels Möller committed
34
35
36
37
   (class
     (name arcfour_instance)
     (super crypto_instance)
     (vars
Niels Möller's avatar
Niels Möller committed
38
       (ctx . "struct arcfour_ctx")))
Niels Möller's avatar
Niels Möller committed
39
40
41
*/
   
static void do_crypt_arcfour(struct crypto_instance *s,
Niels Möller's avatar
Niels Möller committed
42
			     UINT32 length, const UINT8 *src, UINT8 *dst)
Niels Möller's avatar
Niels Möller committed
43
44
45
46
47
48
{
  CAST(arcfour_instance, self, s);

  if (length % 8)
    fatal("Internal error\n");

Niels Möller's avatar
Niels Möller committed
49
  arcfour_crypt(&self->ctx, length, dst, src);
Niels Möller's avatar
Niels Möller committed
50
51
52
}

static struct crypto_instance *
53
54
55
make_arcfour_instance(struct crypto_algorithm *ignored UNUSED,
		      int mode UNUSED,
		      const UINT8 *key, const UINT8 *iv UNUSED)
Niels Möller's avatar
Niels Möller committed
56
57
58
59
60
61
{
  NEW(arcfour_instance, self);

  self->super.block_size = 8;
  self->super.crypt = do_crypt_arcfour;

Niels Möller's avatar
Niels Möller committed
62
  arcfour_set_key(&self->ctx, 16, key);
Niels Möller's avatar
Niels Möller committed
63
64
65
66
67
68
69

  return &self->super;
}

struct crypto_algorithm crypto_arcfour_algorithm =
{ STATIC_HEADER,
  8, 16, 0, make_arcfour_instance };