tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Hacl_Chacha20Poly1305_256.h (3810B)


      1 /* MIT License
      2 *
      3 * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
      4 * Copyright (c) 2022-2023 HACL* Contributors
      5 *
      6 * Permission is hereby granted, free of charge, to any person obtaining a copy
      7 * of this software and associated documentation files (the "Software"), to deal
      8 * in the Software without restriction, including without limitation the rights
      9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     10 * copies of the Software, and to permit persons to whom the Software is
     11 * furnished to do so, subject to the following conditions:
     12 *
     13 * The above copyright notice and this permission notice shall be included in all
     14 * copies or substantial portions of the Software.
     15 *
     16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     22 * SOFTWARE.
     23 */
     24 
     25 #ifndef __Hacl_Chacha20Poly1305_256_H
     26 #define __Hacl_Chacha20Poly1305_256_H
     27 
     28 #if defined(__cplusplus)
     29 extern "C" {
     30 #endif
     31 
     32 #include <string.h>
     33 #include "krml/internal/types.h"
     34 #include "krml/lowstar_endianness.h"
     35 #include "krml/internal/target.h"
     36 
     37 #include "Hacl_Poly1305_256.h"
     38 #include "Hacl_Chacha20_Vec256.h"
     39 
     40 /**
     41 Encrypt a message `m` with key `k`.
     42 
     43 The arguments `k`, `n`, `aadlen`, and `aad` are same in encryption/decryption.
     44 Note: Encryption and decryption can be executed in-place, i.e., `m` and `cipher` can point to the same memory.
     45 
     46 @param k Pointer to 32 bytes of memory where the AEAD key is read from.
     47 @param n Pointer to 12 bytes of memory where the AEAD nonce is read from.
     48 @param aadlen Length of the associated data.
     49 @param aad Pointer to `aadlen` bytes of memory where the associated data is read from.
     50 
     51 @param mlen Length of the message.
     52 @param m Pointer to `mlen` bytes of memory where the message is read from.
     53 @param cipher Pointer to `mlen` bytes of memory where the ciphertext is written to.
     54 @param mac Pointer to 16 bytes of memory where the mac is written to.
     55 */
     56 void
     57 Hacl_Chacha20Poly1305_256_aead_encrypt(
     58    uint8_t *k,
     59    uint8_t *n,
     60    uint32_t aadlen,
     61    uint8_t *aad,
     62    uint32_t mlen,
     63    uint8_t *m,
     64    uint8_t *cipher,
     65    uint8_t *mac);
     66 
     67 /**
     68 Decrypt a ciphertext `cipher` with key `k`.
     69 
     70 The arguments `k`, `n`, `aadlen`, and `aad` are same in encryption/decryption.
     71 Note: Encryption and decryption can be executed in-place, i.e., `m` and `cipher` can point to the same memory.
     72 
     73 If decryption succeeds, the resulting plaintext is stored in `m` and the function returns the success code 0.
     74 If decryption fails, the array `m` remains unchanged and the function returns the error code 1.
     75 
     76 @param k Pointer to 32 bytes of memory where the AEAD key is read from.
     77 @param n Pointer to 12 bytes of memory where the AEAD nonce is read from.
     78 @param aadlen Length of the associated data.
     79 @param aad Pointer to `aadlen` bytes of memory where the associated data is read from.
     80 
     81 @param mlen Length of the ciphertext.
     82 @param m Pointer to `mlen` bytes of memory where the message is written to.
     83 @param cipher Pointer to `mlen` bytes of memory where the ciphertext is read from.
     84 @param mac Pointer to 16 bytes of memory where the mac is read from.
     85 
     86 @returns 0 on succeess; 1 on failure.
     87 */
     88 uint32_t
     89 Hacl_Chacha20Poly1305_256_aead_decrypt(
     90    uint8_t *k,
     91    uint8_t *n,
     92    uint32_t aadlen,
     93    uint8_t *aad,
     94    uint32_t mlen,
     95    uint8_t *m,
     96    uint8_t *cipher,
     97    uint8_t *mac);
     98 
     99 #if defined(__cplusplus)
    100 }
    101 #endif
    102 
    103 #define __Hacl_Chacha20Poly1305_256_H_DEFINED
    104 #endif