Exemplo n.º 1
0
/**
 * Writes the received payload into payload argument and returns the tag of the message
 */
unsigned char server(unsigned char * payload)
{
    ulong msg_len = PAYLOAD_LEN + 1;
    unsigned char* msg = malloc(msg_len);

    // receive the message
    BIO * b = socket_listen();
    recv(b, msg, msg_len);
    // wait for the client to close, to avoid "Address already in use" errors
    wait_close(b);

    unsigned char * pad = otp(msg_len);         // apply the one-time pad
    xor(msg, pad, msg_len);

    // get the payload
    memcpy(payload, msg + 1, PAYLOAD_LEN);

    // return the tag
    return *msg;
}
Exemplo n.º 2
0
Arquivo: otp.c Projeto: robrohan/otp
/**
 * Given cipher text and a key, return the plain text
 */
int otp_decrypt(char * cipher, char * key, char * plain)
{
    return otp(cipher, key, plain, &_otp_mns);
}
Exemplo n.º 3
0
Arquivo: otp.c Projeto: robrohan/otp
/**
 * Given an input string and a key, return an encrypted
 * string
 */
int otp_encrypt(char * plain, char * key, char * cipher)
{
    return otp(plain, key, cipher, &_otp_pls);
}