Skip to content

arc4.h

Functions

Name
int wc_Arc4Process(Arc4 * arc4, byte * out, const byte * in, word32 length)
This function encrypts an input message from the buffer in, placing the ciphertext in the output buffer out, or decrypts a ciphertext from the buffer in, placing the plaintext in the output buffer out, using ARC4 encryption. This function is used for both encryption and decryption. Before this method may be called, one must first initialize the ARC4 structure using wc_Arc4SetKey.
int wc_Arc4SetKey(Arc4 * arc4, const byte * key, word32 length)
This function sets the key for a ARC4 object, initializing it for use as a cipher. It should be called before using it for encryption with wc_Arc4Process.
int wc_Arc4Init(Arc4 * arc4, void * heap, int devId)
This function initializes an ARC4 structure for use with asynchronous cryptographic operations. It sets up the heap hint and device ID for hardware acceleration support.
void wc_Arc4Free(Arc4 * arc4)
This function frees an ARC4 structure, releasing any resources allocated for asynchronous cryptographic operations. It should be called when the ARC4 structure is no longer needed.

Functions Documentation

function wc_Arc4Process

int wc_Arc4Process(
    Arc4 * arc4,
    byte * out,
    const byte * in,
    word32 length
)

This function encrypts an input message from the buffer in, placing the ciphertext in the output buffer out, or decrypts a ciphertext from the buffer in, placing the plaintext in the output buffer out, using ARC4 encryption. This function is used for both encryption and decryption. Before this method may be called, one must first initialize the ARC4 structure using wc_Arc4SetKey.

Parameters:

  • arc4 pointer to the ARC4 structure used to process the message
  • out pointer to the output buffer in which to store the processed message
  • in pointer to the input buffer containing the message to process
  • length length of the message to process

See: wc_Arc4SetKey

Return: none

Example

Arc4 enc;
byte key[] = { key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));

byte plain[] = { plain text to encode };
byte cipher[sizeof(plain)];
byte decrypted[sizeof(plain)];
// encrypt the plain into cipher
wc_Arc4Process(&enc, cipher, plain, sizeof(plain));
// decrypt the cipher
wc_Arc4Process(&enc, decrypted, cipher, sizeof(cipher));

function wc_Arc4SetKey

int wc_Arc4SetKey(
    Arc4 * arc4,
    const byte * key,
    word32 length
)

This function sets the key for a ARC4 object, initializing it for use as a cipher. It should be called before using it for encryption with wc_Arc4Process.

Parameters:

  • arc4 pointer to an arc4 structure to be used for encryption
  • key key with which to initialize the arc4 structure
  • length length of the key used to initialize the arc4 structure

See: wc_Arc4Process

Return: none

Example

Arc4 enc;
byte key[] = { initialize with key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));

function wc_Arc4Init

int wc_Arc4Init(
    Arc4 * arc4,
    void * heap,
    int devId
)

This function initializes an ARC4 structure for use with asynchronous cryptographic operations. It sets up the heap hint and device ID for hardware acceleration support.

Parameters:

  • arc4 pointer to the Arc4 structure to initialize
  • heap pointer to heap hint for memory allocation (can be NULL)
  • devId device ID for hardware acceleration (use INVALID_DEVID for software)

See:

Return:

  • 0 On success.
  • BAD_FUNC_ARG If arc4 is NULL.

Example

Arc4 arc4;
int ret = wc_Arc4Init(&arc4, NULL, INVALID_DEVID);
if (ret != 0) {
    // initialization failed
}
// use arc4 for encryption/decryption
wc_Arc4Free(&arc4);

function wc_Arc4Free

void wc_Arc4Free(
    Arc4 * arc4
)

This function frees an ARC4 structure, releasing any resources allocated for asynchronous cryptographic operations. It should be called when the ARC4 structure is no longer needed.

Parameters:

  • arc4 pointer to the Arc4 structure to free

See:

Return: none No return value.

Example

Arc4 arc4;
wc_Arc4Init(&arc4, NULL, INVALID_DEVID);
wc_Arc4SetKey(&arc4, key, keyLen);
// use arc4 for encryption/decryption
wc_Arc4Free(&arc4);

Source code


int wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length);

int wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length);

int wc_Arc4Init(Arc4* arc4, void* heap, int devId);

void wc_Arc4Free(Arc4* arc4);

Updated on 2025-12-31 at 01:16:03 +0000