OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [trunk/] [tests/] [rc4test.c] - Blame information for rev 107

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 73 ghutchis
//
2
// Copyright (c) 2005 Guy Hutchison (ghutchis@opencores.org)
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a 
5
// copy of this software and associated documentation files (the "Software"), 
6
// to deal in the Software without restriction, including without limitation 
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8
// and/or sell copies of the Software, and to permit persons to whom the 
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included 
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
18
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
20
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
//
22
 
23
#include "tv80_env.h"
24
#include "rc4.h"
25
#include "stdint.h"
26
 
27
#define BUFSIZE 128
28
 
29
int main ()
30
{
31
  struct rc4_state rs;
32
  uint8_t key[16];
33
  int i;
34
  uint8_t pass;
35
  uint8_t buf1[BUFSIZE], buf2[BUFSIZE], buf3[BUFSIZE];
36
 
37
  print ("Start\n");
38
  // initialize key
39
  for (i=0; i<16; i++)
40
    key[i] = i;
41
 
42
  // init buf1
43
  for (i=0; i<BUFSIZE; i++)
44
    buf1[i] = i;
45
 
46
  // encrypt buf1->buf2
47
  print ("EncInit\n");
48
  rc4_init (&rs, key, 16);
49
  print ("Encrypting\n");
50
  rc4_crypt (&rs, buf1, buf2, BUFSIZE);
51
 
52
  // decrypt buf2->buf3
53
  print ("DecInit\n");
54
  rc4_init (&rs, key, 16);
55
  print ("Decrypting\n");
56
  rc4_crypt (&rs, buf2, buf3, BUFSIZE);
57
 
58
  // compare buf1 == buf3
59
  print ("Comparing\n");
60
  pass = 1;
61
  for (i=0; i<BUFSIZE; i++)
62
    if (buf1[i] != buf3[i])
63
      pass = 0;
64
 
65
  if (pass)
66
    sim_ctl_port = SC_TEST_PASSED;
67
  else
68
    sim_ctl_port = SC_TEST_FAILED;
69
 
70
  return 0;
71
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.