ReactOS 0.4.16-dev-92-g0c2cdca
rc4.c File Reference
#include "tomcrypt.h"
Include dependency graph for rc4.c:

Go to the source code of this file.

Functions

int rc4_start (prng_state *prng)
 
int rc4_add_entropy (const unsigned char *buf, unsigned long len, prng_state *prng)
 
int rc4_ready (prng_state *prng)
 
unsigned long rc4_read (unsigned char *buf, unsigned long len, prng_state *prng)
 

Function Documentation

◆ rc4_add_entropy()

int rc4_add_entropy ( const unsigned char buf,
unsigned long  len,
prng_state prng 
)

Definition at line 41 of file rc4.c.

42{
43 /* trim as required */
44 if (prng->rc4.x + len > 256) {
45 if (prng->rc4.x == 256) {
46 /* I can't possibly accept another byte, ok maybe a mint wafer... */
47 return CRYPT_OK;
48 } else {
49 /* only accept part of it */
50 len = 256 - prng->rc4.x;
51 }
52 }
53
54 while (len--) {
55 prng->rc4.buf[prng->rc4.x++] = *buf++;
56 }
57
58 return CRYPT_OK;
59}
@ CRYPT_OK
Definition: tomcrypt.h:43
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
struct rc4_prng rc4
Definition: tomcrypt.h:168

Referenced by setup_key_impl().

◆ rc4_read()

unsigned long rc4_read ( unsigned char buf,
unsigned long  len,
prng_state prng 
)

Definition at line 89 of file rc4.c.

90{
91 unsigned char x, y, *s, tmp;
92 unsigned long n;
93
94 n = len;
95 x = prng->rc4.x;
96 y = prng->rc4.y;
97 s = prng->rc4.buf;
98 while (len--) {
99 x = (x + 1) & 255;
100 y = (y + s[x]) & 255;
101 tmp = s[x]; s[x] = s[y]; s[y] = tmp;
102 tmp = (s[x] + s[y]) & 255;
103 *buf++ ^= s[tmp];
104 }
105 prng->rc4.x = x;
106 prng->rc4.y = y;
107 return n;
108}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729

Referenced by encrypt_stream_impl().

◆ rc4_ready()

int rc4_ready ( prng_state prng)

Definition at line 61 of file rc4.c.

62{
63 unsigned char key[256], tmp, *s;
64 int keylen, x, y, j;
65
66 /* extract the key */
67 s = prng->rc4.buf;
68 memcpy(key, s, 256);
69 keylen = prng->rc4.x;
70
71 /* make RC4 perm and shuffle */
72 for (x = 0; x < 256; x++) {
73 s[x] = x;
74 }
75
76 for (j = x = y = 0; x < 256; x++) {
77 y = (y + prng->rc4.buf[x] + key[j++]) & 255;
78 if (j == keylen) {
79 j = 0;
80 }
81 tmp = s[x]; s[x] = s[y]; s[y] = tmp;
82 }
83 prng->rc4.x = 0;
84 prng->rc4.y = 0;
85
86 return CRYPT_OK;
87}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: copy.c:22

Referenced by setup_key_impl().

◆ rc4_start()

int rc4_start ( prng_state prng)

Definition at line 33 of file rc4.c.

34{
35 /* set keysize to zero */
36 prng->rc4.x = 0;
37
38 return CRYPT_OK;
39}

Referenced by setup_key_impl().