| 1 |
/* |
| 2 |
* This file is part of the SSH Library |
| 3 |
* |
| 4 |
* Copyright (c) 2021 by Anderson Toshiyuki Sasaki - Red Hat, Inc. |
| 5 |
* |
| 6 |
* The SSH Library is free software: you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation, either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* The SSH Library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with the SSH Library; see the file COPYING. If not, |
| 18 |
* see <https://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdint.h> |
| 25 |
#include <stdio.h> |
| 26 |
#include <libssh/chacha.h> |
| 27 |
#include <libssh/priv.h> |
| 28 |
|
| 29 |
#include "chacha20_override.h" |
| 30 |
|
| 31 |
static bool internal_function_called = false; |
| 32 |
|
| 33 |
void __wrap_chacha_keysetup(struct chacha_ctx *x, |
| 34 |
const uint8_t *k, |
| 35 |
uint32_t kbits) |
| 36 |
#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE |
| 37 |
__attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))) |
| 38 |
#endif |
| 39 |
{ |
| 40 |
fprintf(stderr, "%s: Internal implementation was called\n", __func__); |
| 41 |
internal_function_called = true; |
| 42 |
chacha_keysetup(x, k, kbits); |
| 43 |
} |
| 44 |
|
| 45 |
void __wrap_chacha_ivsetup(struct chacha_ctx *x, |
| 46 |
const uint8_t *iv, |
| 47 |
const uint8_t *ctr) |
| 48 |
#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE |
| 49 |
__attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) |
| 50 |
__attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))) |
| 51 |
#endif |
| 52 |
{ |
| 53 |
fprintf(stderr, "%s: Internal implementation was called\n", __func__); |
| 54 |
internal_function_called = true; |
| 55 |
chacha_ivsetup(x, iv, ctr); |
| 56 |
} |
| 57 |
|
| 58 |
void __wrap_chacha_encrypt_bytes(struct chacha_ctx *x, |
| 59 |
const uint8_t *m, |
| 60 |
uint8_t *c, |
| 61 |
uint32_t bytes) |
| 62 |
#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE |
| 63 |
__attribute__((__bounded__(__buffer__, 2, 4))) |
| 64 |
__attribute__((__bounded__(__buffer__, 3, 4))) |
| 65 |
#endif |
| 66 |
{ |
| 67 |
fprintf(stderr, "%s: Internal implementation was called\n", __func__); |
| 68 |
internal_function_called = true; |
| 69 |
chacha_encrypt_bytes(x, m, c, bytes); |
| 70 |
} |
| 71 |
|
| 72 |
bool internal_chacha20_function_called(void) |
| 73 |
{ |
| 74 |
return internal_function_called; |
| 75 |
} |
| 76 |
|
| 77 |
void reset_chacha20_function_called(void) |
| 78 |
{ |
| 79 |
internal_function_called = false; |
| 80 |
} |