File: arc4.h

package info (click to toggle)
sfs 1%3A0.8-0%2Bpre20060720.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,668 kB
  • ctags: 14,317
  • sloc: cpp: 78,358; ansic: 15,494; sh: 9,540; yacc: 786; makefile: 706; perl: 676; lex: 553; python: 146; sed: 70
file content (66 lines) | stat: -rw-r--r-- 1,762 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// -*-c++-*-
/* $Id: arc4.h,v 1.2 1998/11/10 21:36:06 dm Exp $ */

/*
 *
 * Copyright (C) 1998 David Mazieres (dm@uun.org)
 *
 * 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, 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */


#ifndef _ARC4_H_
#define _ARC4_H_

#include "sysconf.h"

/* Arcfour random stream generator.  This code is derived from section
 * 17.1 of Applied Cryptography, second edition, which describes a
 * stream cipher allegedly compatible with RSA Labs "RC4" cipher (the
 * actual description of which is a trade secret).  The same algorithm
 * is used as a stream cipher called "arcfour" in Tatu Ylonen's ssh
 * package.
 *
 * RC4 is a registered trademark of RSA Laboratories.
 */

class arc4 {
  u_char i;
  u_char j;
  u_char s[256];

  void _setkey (const u_char *key, size_t len);

public:
  arc4 () { reset (); }
  ~arc4 () { i = j = 0; bzero (s, sizeof (s)); }

  void reset ();
  void setkey (const void *key, size_t len);

  u_char getbyte () {
    i = i + 1 & 0xff;
    u_char si = s[i];
    j = j + si & 0xff;
    u_char sj = s[j];
    s[i] = sj;
    s[j] = si;
    return s[si + sj & 0xff];
  }
};

#endif /* _ARC4_H_ */