Esempio n. 1
0
int main(void) {
  uint8_t rc4State[256]; // RC4 state
  const uint8_t rc4Key[132] = "This is a key that I am typing in so that I have something to test with, and then I can start testing. I just need more characters.";

  uint8_t key[LIGHTMAC_KEY_LENGTH];

  uint8_t singleblock[L_BLOCK_LENGTH];
  unsigned int singleblockLength = L_BLOCK_LENGTH;

  uint8_t multiblock[4*L_BLOCK_LENGTH];
  unsigned int multiblockLength = 4*L_BLOCK_LENGTH;

  uint8_t empty[0] = {};

  unsigned int smallfractionalLength = L_BLOCK_LENGTH-1;
  uint8_t smallfractional[L_BLOCK_LENGTH-1];

  unsigned int largefractionalLength = 4*L_BLOCK_LENGTH-1;
  uint8_t largefractional[4*L_BLOCK_LENGTH-1];

  printf("Maximum message length: %llu bytes.\n", maxMessageLength());

  arcfour_key_setup(rc4State, rc4Key, 131);

  arcfour_generate_stream(rc4State, key, LIGHTMAC_KEY_LENGTH);
  arcfour_generate_stream(rc4State, singleblock, singleblockLength);
  basicTests(singleblock, singleblockLength, key, "Single block");

  arcfour_generate_stream(rc4State, key, LIGHTMAC_KEY_LENGTH);
  arcfour_generate_stream(rc4State, multiblock, multiblockLength);
  basicTests(multiblock, multiblockLength, key, "Multi block");

  arcfour_generate_stream(rc4State, key, LIGHTMAC_KEY_LENGTH);
  basicTests(empty, 0, key, "Empty string");

  arcfour_generate_stream(rc4State, key, LIGHTMAC_KEY_LENGTH);
  arcfour_generate_stream(rc4State, smallfractional, smallfractionalLength);
  basicTests(smallfractional, smallfractionalLength, key, "Small fractional message");

  arcfour_generate_stream(rc4State, key, LIGHTMAC_KEY_LENGTH);
  arcfour_generate_stream(rc4State, largefractional, largefractionalLength);
  basicTests(largefractional, largefractionalLength, key, "Large fractional message");

}
Esempio n. 2
0
int main(int argc, char **argv) {
    unsigned char buffer[101];
    unsigned char state[256];
    char* key = argv[1];

    // Checking license
    if (!file_exist("/etc/arc42_license")) {
        fprintf(stderr, "Sorry, your ARC42 copy is not licensed. :'(\n");
        return 1;
    }

    // Checking the key argument
    if (argc < 2) {
        fprintf(stderr, "Please provide a key as argument.\n");
        return 2;
    }
    if (strlen(key) > 255) {
        fprintf(stderr, "The key is too long. Maximum size is 255 characters.\n");
        return 3;
    }

    // Initialization
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);
    arcfour_key_setup(state, (unsigned char*)key, strlen(key));
    while (*key) *(key++) = 0;

    // Encryption
    int i, j, c = 0;
    while (c != -1) {
        // Read in max. 100 bytes
        for (i = 0; i < 100 && ((c = getchar()) != -1); i++) {
            buffer[i] = c;
        }

        // Encrypt the buffer
        for (j = 0; j < i; j++) {
            unsigned char xor;
            arcfour_generate_stream(state, &xor, 1);
            buffer[j] ^= xor;
        }

        // Print out the encrypted data
        buffer[j] = 0;
        printf((char*)buffer);
    }

    return 0;
}