exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

rc62.c

rc62.c
Posted Dec 21, 1999

rc62.c

tags | encryption
SHA-256 | 05233a45fc0d19749e485bc74e90f9715d0e057f000e7e4b743f5662ac558408

rc62.c

Change Mirror Download

/* This is an independent implementation of the RC6 algorithm that */
/* Ron Rivest and RSA Labs have submitted as a candidate for the */
/* NIST AES activity. Refer to RSA Labs and Ron Rivest for any */
/* copyright, patent or license issues for the RC6 algorithm. */
/* */
/* Copyright in this implementation is held by Dr B R Gladman but */
/* I hereby give permission for its free direct or derivative use */
/* subject to acknowledgment of its origin and compliance with any */
/* constraints that are placed on the exploitation of RC6 by its */
/* designers. */
/* */
/* Dr Brian Gladman (gladman@seven77.demon.co.uk) 18th July 1998 */
/*
Timing data:

Algorithm: rc6 (rc62.c)
128 bit key:
Key Setup: 1584 cycles
Encrypt: 251 cycles = 102.0 mbits/sec
Decrypt: 239 cycles = 107.1 mbits/sec
Mean: 245 cycles = 104.5 mbits/sec
192 bit key:
Key Setup: 1877 cycles
Encrypt: 255 cycles = 100.5 mbits/sec
Decrypt: 248 cycles = 103.2 mbits/sec
Mean: 251 cycles = 101.9 mbits/sec
256 bit key:
Key Setup: 1779 cycles
Encrypt: 244 cycles = 104.8 mbits/sec
Decrypt: 239 cycles = 107.1 mbits/sec
Mean: 242 cycles = 105.9 mbits/sec

*/

#include "../std_defs.h"

static char *alg_name[] = { "rc6", "rc62.c" };

char **cipher_name()
{
return alg_name;
}

#define f_rnd(i,a,b,c,d) \
t = b * (b + b + 1); \
u = d * (d + d + 1); \
a = rotl(a ^ rotl(t,5), u); \
c = rotl(c ^ rotl(u,5), t); \
a += l_key[i]; \
c += l_key[i + 1] \

#define i_rnd(i,a,b,c,d) \
u = rotl(d * (d + d + 1), 5); \
t = rotl(b * (b + b + 1), 5); \
c = rotr(c - l_key[i + 1], t) ^ u; \
a = rotr(a - l_key[i], u) ^ t \

u4byte l_key[44]; /* storage for the key schedule */

/* initialise the key schedule from the user supplied key */

u4byte *set_key(const u4byte in_key[], const u4byte key_len)
{ u4byte i, j, k, a, b, l[8], t;

l_key[0] = 0xb7e15163;

for(k = 1; k < 44; ++k)

l_key[k] = l_key[k - 1] + 0x9e3779b9;

for(k = 0; k < key_len / 32; ++k)

l[k] = in_key[k];

t = (key_len / 32) - 1;

a = b = i = j = 0;

for(k = 0; k < 132; ++k)
{ a = rotl(l_key[i] + a + b, 3); b += a;
b = rotl(l[j] + b, b);
l_key[i] = a; l[j] = b;
i = (i == 43 ? 0 : i + 1);
j = (j == t ? 0 : j + 1);
}

return l_key;
};

/* encrypt a block of text */

void encrypt(const u4byte in_blk[4], u4byte out_blk[4])
{ u4byte a,b,c,d,t,u;

a = in_blk[0]; b = in_blk[1] + l_key[0];
c = in_blk[2]; d = in_blk[3] + l_key[1];

f_rnd( 2,a,b,c,d); f_rnd( 4,b,c,d,a);
f_rnd( 6,c,d,a,b); f_rnd( 8,d,a,b,c);
f_rnd(10,a,b,c,d); f_rnd(12,b,c,d,a);
f_rnd(14,c,d,a,b); f_rnd(16,d,a,b,c);
f_rnd(18,a,b,c,d); f_rnd(20,b,c,d,a);
f_rnd(22,c,d,a,b); f_rnd(24,d,a,b,c);
f_rnd(26,a,b,c,d); f_rnd(28,b,c,d,a);
f_rnd(30,c,d,a,b); f_rnd(32,d,a,b,c);
f_rnd(34,a,b,c,d); f_rnd(36,b,c,d,a);
f_rnd(38,c,d,a,b); f_rnd(40,d,a,b,c);

out_blk[0] = a + l_key[42]; out_blk[1] = b;
out_blk[2] = c + l_key[43]; out_blk[3] = d;
};

/* decrypt a block of text */

void decrypt(const u4byte in_blk[4], u4byte out_blk[4])
{ u4byte a,b,c,d,t,u;

d = in_blk[3]; c = in_blk[2] - l_key[43];
b = in_blk[1]; a = in_blk[0] - l_key[42];

i_rnd(40,d,a,b,c); i_rnd(38,c,d,a,b);
i_rnd(36,b,c,d,a); i_rnd(34,a,b,c,d);
i_rnd(32,d,a,b,c); i_rnd(30,c,d,a,b);
i_rnd(28,b,c,d,a); i_rnd(26,a,b,c,d);
i_rnd(24,d,a,b,c); i_rnd(22,c,d,a,b);
i_rnd(20,b,c,d,a); i_rnd(18,a,b,c,d);
i_rnd(16,d,a,b,c); i_rnd(14,c,d,a,b);
i_rnd(12,b,c,d,a); i_rnd(10,a,b,c,d);
i_rnd( 8,d,a,b,c); i_rnd( 6,c,d,a,b);
i_rnd( 4,b,c,d,a); i_rnd( 2,a,b,c,d);

out_blk[3] = d - l_key[1]; out_blk[2] = c;
out_blk[1] = b - l_key[0]; out_blk[0] = a;
};
Login or Register to add favorites

File Archive:

September 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Sep 1st
    261 Files
  • 2
    Sep 2nd
    17 Files
  • 3
    Sep 3rd
    38 Files
  • 4
    Sep 4th
    52 Files
  • 5
    Sep 5th
    23 Files
  • 6
    Sep 6th
    27 Files
  • 7
    Sep 7th
    0 Files
  • 8
    Sep 8th
    1 Files
  • 9
    Sep 9th
    16 Files
  • 10
    Sep 10th
    38 Files
  • 11
    Sep 11th
    21 Files
  • 12
    Sep 12th
    40 Files
  • 13
    Sep 13th
    18 Files
  • 14
    Sep 14th
    0 Files
  • 15
    Sep 15th
    0 Files
  • 16
    Sep 16th
    21 Files
  • 17
    Sep 17th
    51 Files
  • 18
    Sep 18th
    23 Files
  • 19
    Sep 19th
    48 Files
  • 20
    Sep 20th
    36 Files
  • 21
    Sep 21st
    0 Files
  • 22
    Sep 22nd
    0 Files
  • 23
    Sep 23rd
    0 Files
  • 24
    Sep 24th
    0 Files
  • 25
    Sep 25th
    0 Files
  • 26
    Sep 26th
    0 Files
  • 27
    Sep 27th
    0 Files
  • 28
    Sep 28th
    0 Files
  • 29
    Sep 29th
    0 Files
  • 30
    Sep 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close