internal-wage.h 3.48 KB
Newer Older
Rhys Weatherley committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/*
 * Copyright (C) 2020 Southern Storm Software, Pty Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef LW_INTERNAL_WAGE_H
#define LW_INTERNAL_WAGE_H

#include "internal-util.h"

/**
 * \file internal-wage.h
 * \brief Internal implementation of the WAGE permutation.
 *
 * References: https://uwaterloo.ca/communications-security-lab/lwc/wage
 */

#ifdef __cplusplus
extern "C" {
#endif

/**
 * \brief Size of the WAGE state in bytes.
 *
 * The state is 259 bits, divided into 37 7-bit components, one per byte.
 */
#define WAGE_STATE_SIZE 37

/**
 * \brief Permutes the WAGE state.
 *
 * \param s The WAGE state to be permuted.
 */
void wage_permute(unsigned char s[WAGE_STATE_SIZE]);

/**
 * \brief Absorbs 8 bytes into the WAGE state.
 *
 * \param s The WAGE state to be permuted.
 * \param data The data to be absorbed.
 * \param domain The domain separator for the absorbed data.
 */
void wage_absorb
    (unsigned char s[WAGE_STATE_SIZE], const unsigned char data[8],
     unsigned char domain);

/**
 * \brief Gets the 8 bytes of the rate from the WAGE state.
 *
 * \param s The WAGE state to get the bytes from.
 * \param data Points to the buffer to receive the extracted bytes.
 */
void wage_get_rate
    (const unsigned char s[WAGE_STATE_SIZE], unsigned char data[8]);

/**
 * \brief Sets the 8 bytes of the rate in the WAGE state.
 *
 * \param s The WAGE state to set the rate in.
 * \param data Points to the bytes to set into the rate.
 * \param domain The domain separator for the rate data.
 */
void wage_set_rate
    (unsigned char s[WAGE_STATE_SIZE], const unsigned char data[8],
     unsigned char domain);

/**
 * \brief Absorbs 16 key bytes into the WAGE state.
 *
 * \param s The WAGE state to be permuted.
 * \param key Points to the key data to be absorbed.
 */
void wage_absorb_key
    (unsigned char s[WAGE_STATE_SIZE], const unsigned char *key);

/**
 * \brief Initializes the WAGE state with a key and nonce.
 *
 * \param s The WAGE state to be initialized.
 * \param key Points to the 128-bit key.
 * \param nonce Points to the 128-bit nonce.
 */
void wage_init
    (unsigned char s[WAGE_STATE_SIZE],
     const unsigned char *key, const unsigned char *nonce);

/**
 * \brief Extracts the 128-bit authentication tag from the WAGE state.
 *
 * \param s The WAGE state to extract the tag from.
 * \param tag Points to the buffer to receive the extracted tag.
 */
void wage_extract_tag
    (const unsigned char s[WAGE_STATE_SIZE], unsigned char tag[16]);

#ifdef __cplusplus
}
#endif

#endif