~ubuntu-branches/ubuntu/intrepid/parted/intrepid

« back to all changes in this revision

Viewing changes to gnulib/lib/arcfour.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-24 14:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080624143105-rd7yw67a9qnvh51i
Tags: 1.8.8.git.2008.03.24-7ubuntu1
* Resynchronise with Debian (LP: #237568). Remaining changes:
  - swap-uuid.dpatch: Create UUIDs on new swap partitions.
  - gptsync.dpatch: On Intel Mac systems, write a synced MBR rather than a
    protective MBR.
  - Add -fno-stack-protector on sparc.
  - sparc-new-label.dpatch: Fix sparc disk label generation. This is
    required for LDOM and parallel installations with Solaris 10.
  - loop-partitions.dpatch: Loop devices can only have one partition, so
    don't generate device names such as "/dev/loop0p1".
  - unpartitioned-disks.dpatch: Don't try to call BLKPG ioctls on
    unpartitionable disks (only implemented for loop devices at the
    moment), as they will always fail.
  - When building with gcc-4.3, add -Wno-array-bounds to CFLAGS.
  - Cell partition tables are misdetected as pc98, so disable pc98 support
    on powerpc.
  - array-bounds.dpatch: Backport patch from git to allow building with
    gcc-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* arcfour.c --- The arcfour stream cipher
 
2
 * Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software
 
3
 * Foundation, Inc.
 
4
 *
 
5
 * This file is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published
 
7
 * by the Free Software Foundation; either version 2, or (at your
 
8
 * option) any later version.
 
9
 *
 
10
 * This file is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this file; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
 * 02110-1301, USA.
 
19
 *
 
20
 */
 
21
 
 
22
/* Code from Libgcrypt adapted for gnulib by Simon Josefsson. */
 
23
 
 
24
/*
 
25
 * For a description of the algorithm, see:
 
26
 *   Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996.
 
27
 *   ISBN 0-471-11709-9. Pages 397 ff.
 
28
 */
 
29
 
 
30
#include <config.h>
 
31
 
 
32
#include "arcfour.h"
 
33
 
 
34
void
 
35
arcfour_stream (arcfour_context * context, const char *inbuf, char *outbuf,
 
36
                size_t length)
 
37
{
 
38
  uint8_t i = context->idx_i;
 
39
  uint8_t j = context->idx_j;
 
40
  char *sbox = context->sbox;
 
41
 
 
42
  for (; length > 0; length--)
 
43
    {
 
44
      char t;
 
45
 
 
46
      i++;
 
47
      j += sbox[i];
 
48
      t = sbox[i];
 
49
      sbox[i] = sbox[j];
 
50
      sbox[j] = t;
 
51
      *outbuf++ = (*inbuf++
 
52
                   ^ sbox[(0U + sbox[i] + sbox[j]) % ARCFOUR_SBOX_SIZE]);
 
53
    }
 
54
 
 
55
  context->idx_i = i;
 
56
  context->idx_j = j;
 
57
}
 
58
 
 
59
void
 
60
arcfour_setkey (arcfour_context * context, const char *key, size_t keylen)
 
61
{
 
62
  size_t i, j, k;
 
63
  char *sbox = context->sbox;
 
64
 
 
65
  context->idx_i = context->idx_j = 0;
 
66
  for (i = 0; i < ARCFOUR_SBOX_SIZE; i++)
 
67
    sbox[i] = i;
 
68
  for (i = j = k = 0; i < ARCFOUR_SBOX_SIZE; i++)
 
69
    {
 
70
      char t;
 
71
      j = (j + sbox[i] + key[k]) % ARCFOUR_SBOX_SIZE;
 
72
      t = sbox[i];
 
73
      sbox[i] = sbox[j];
 
74
      sbox[j] = t;
 
75
      if (++k == keylen)
 
76
        k = 0;
 
77
    }
 
78
}