--- /dev/null
+/* Copyright (C) 2021 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+use std::os::raw::c_uchar;
+use libc::c_ulong;
+
+#[repr(C)]
+#[allow(non_camel_case_types)]
+pub enum Base64ReturnCode {
+ SC_BASE64_OK = 0,
+ SC_BASE64_INVALID_ARG,
+ SC_BASE64_OVERFLOW,
+}
+
+/// Base64 encode a buffer.
+///
+/// This method exposes the Rust base64 encoder to C and should not be called from
+/// Rust code.
+///
+/// The output parameter must be an allocated buffer of at least the size returned
+/// from Base64EncodeBufferSize for the input_len, and this length must be provided
+/// in the output_len variable.
+#[no_mangle]
+pub unsafe extern "C" fn Base64Encode(
+ input: *const u8, input_len: c_ulong, output: *mut c_uchar, output_len: *mut c_ulong,
+) -> Base64ReturnCode {
+ if input.is_null() || output.is_null() || output_len.is_null() {
+ return Base64ReturnCode::SC_BASE64_INVALID_ARG;
+ }
+ let input = std::slice::from_raw_parts(input, input_len as usize);
+ let encoded = base64::encode(input);
+ if encoded.len() + 1 > *output_len as usize {
+ return Base64ReturnCode::SC_BASE64_OVERFLOW;
+ }
+ let output = std::slice::from_raw_parts_mut(&mut *(output as *mut u8), *output_len as usize);
+ output[0..encoded.len()].copy_from_slice(encoded.as_bytes());
+ output[encoded.len()] = 0;
+ *output_len = encoded.len() as c_ulong;
+ Base64ReturnCode::SC_BASE64_OK
+}
+
+/// Ratio of output bytes to input bytes for Base64 Encoding is 4:3, hence the
+/// required output bytes are 4 * ceil(input_len / 3) and an additional byte for
+/// storing the NULL pointer.
+#[no_mangle]
+pub extern "C" fn Base64EncodeBufferSize(len: c_ulong) -> c_ulong {
+ (4 * ((len) + 2) / 3) + 1
+}
*/
pub mod hashing;
+pub mod base64;
#include "suricata-common.h"
-#include "util-crypt.h"
-
#include "app-layer-dnp3.h"
#include "app-layer-dnp3-objects.h"
#include "output-json-dnp3-objects.h"
util-config.h \
util-coredump-config.h \
util-cpu.h \
- util-crypt.h \
util-daemon.h \
util-debug-filters.h \
util-debug.h \
util-conf.c \
util-coredump-config.c \
util-cpu.c \
- util-crypt.c \
util-daemon.c \
util-debug.c \
util-debug-filters.c \
#include "decode-events.h"
#include "conf.h"
-#include "util-crypt.h"
#include "util-spm.h"
#include "util-unittest.h"
#include "util-debug.h"
#include "datasets-md5.h"
#include "util-thash.h"
#include "util-print.h"
-#include "util-crypt.h" // encode base64
#include "util-base64.h" // decode base64
int Md5StrSet(void *dst, void *src)
#include "datasets-sha256.h"
#include "util-thash.h"
#include "util-print.h"
-#include "util-crypt.h" // encode base64
#include "util-base64.h" // decode base64
int Sha256StrSet(void *dst, void *src)
#include "datasets-string.h"
#include "util-thash.h"
#include "util-print.h"
-#include "util-crypt.h" // encode base64
#include "util-base64.h" // decode base64
+#include "rust.h"
#if 0
static int StringAsAscii(const void *s, char *out, size_t out_size)
{
const StringType *str = s;
- unsigned long len = BASE64_BUFFER_SIZE(str->len);
+ unsigned long len = Base64EncodeBufferSize(str->len);
uint8_t encoded_data[len];
if (Base64Encode((unsigned char *)str->ptr, str->len,
encoded_data, &len) != SC_BASE64_OK)
#include "datasets-reputation.h"
#include "util-thash.h"
#include "util-print.h"
-#include "util-crypt.h" // encode base64
#include "util-base64.h" // decode base64
#include "util-byte.h"
#include "util-misc.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "util-time.h"
#include "log-cf-common.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "util-time.h"
#define MODULE_NAME "LogTlsStoreLog"
}
TAILQ_FOREACH(cert, &state->server_connp.certs, next) {
- pemlen = BASE64_BUFFER_SIZE(cert->cert_len);
+ pemlen = Base64EncodeBufferSize(cert->cert_len);
if (pemlen > aft->enc_buf_len) {
ptmp = (uint8_t*) SCRealloc(aft->enc_buf, sizeof(uint8_t) * pemlen);
if (ptmp == NULL) {
#include "util-proto-name.h"
#include "util-optimize.h"
#include "util-buffer.h"
-#include "util-crypt.h"
#include "util-validate.h"
#define MODULE_NAME "JsonAlertLog"
#include "util-proto-name.h"
#include "util-optimize.h"
#include "util-buffer.h"
-#include "util-crypt.h"
#include "util-validate.h"
#define MODULE_NAME "JsonAnomalyLog"
#include "suricata-common.h"
-#include "util-crypt.h"
-
#include "app-layer-dnp3.h"
#include "app-layer-dnp3-objects.h"
#include "output-json-dnp3-objects.h"
#include "util-print.h"
#include "util-unittest.h"
#include "util-buffer.h"
-#include "util-crypt.h"
#include "util-debug.h"
#include "app-layer.h"
#include "util-byte.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "output-json.h"
#include "output-json-email-common.h"
#include "util-proto-name.h"
#include "util-logopenfile.h"
#include "util-time.h"
-#include "util-crypt.h"
#include "output-json.h"
#include "output-json-alert.h"
#include "output-json-http.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "output-json.h"
#include "output-json-http2.h"
#include "util-proto-name.h"
#include "util-optimize.h"
#include "util-buffer.h"
-#include "util-crypt.h"
#define MODULE_NAME "JsonMetadataLog"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "output-json.h"
#include "output-json-ssh.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "output-json.h"
#include "output-json-stats.h"
#include "util-buffer.h"
#include "util-logopenfile.h"
-#include "util-crypt.h"
#include "util-ja3.h"
#include "output-json.h"
#include "util-log-redis.h"
#include "util-device.h"
#include "util-validate.h"
-#include "util-crypt.h"
#include "util-plugin.h"
#include "flow-var.h"
+++ /dev/null
-/* Copyright (C) 2007-2012 Open Information Security Foundation
- *
- * You can copy, redistribute or modify this Program under the terms of
- * the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-/**
- * \file
- *
- * \author Roliers Jean-Paul <popof.fpn@gmail.co>
- *
- * Implements cryptographic functions.
- * Based on the libtomcrypt library ( http://libtom.org/?page=features&newsitems=5&whatfile=crypt )
- *
- * Implementation of function using NSS is not linked with libtomcrypt.
- */
-
-#include "suricata-common.h"
-#include "suricata.h"
-#include "util-crypt.h"
-
-static const char *b64codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-int Base64Encode(const unsigned char *in, unsigned long inlen,
- unsigned char *out, unsigned long *outlen)
-{
- unsigned long i, len2, leven;
- unsigned char *p;
- if(in == NULL || out == NULL || outlen == NULL)
- {
- return SC_BASE64_INVALID_ARG;
- }
- /* valid output size ? */
- len2 = 4 * ((inlen + 2) / 3);
- if (*outlen < len2 + 1) {
- *outlen = len2 + 1;
- return SC_BASE64_OVERFLOW;
- }
- p = out;
- leven = 3*(inlen / 3);
- for (i = 0; i < leven; i += 3) {
- *p++ = b64codes[(in[0] >> 2) & 0x3F];
- *p++ = b64codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
- *p++ = b64codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
- *p++ = b64codes[in[2] & 0x3F];
- in += 3;
- }
- /* Pad it if necessary... */
- if (i < inlen) {
- unsigned a = in[0];
- unsigned b = (i+1 < inlen) ? in[1] : 0;
-
- *p++ = b64codes[(a >> 2) & 0x3F];
- *p++ = b64codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
- *p++ = (i+1 < inlen) ? b64codes[(((b & 0xf) << 2)) & 0x3F] : '=';
- *p++ = '=';
- }
- /* append a NULL byte */
- *p = '\0';
- /* return ok */
- *outlen = p - out;
- return SC_BASE64_OK;
-}
+++ /dev/null
-/* Copyright (C) 2007-2012 Open Information Security Foundation
- *
- * You can copy, redistribute or modify this Program under the terms of
- * the GNU General Public License version 2 as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-/**
- * \file
- *
- * \author Roliers Jean-Paul <popof.fpn@gmail.co>
- *
- * Implements cryptographic functions.
- * Based on the libtomcrypt library ( http://libtom.org/?page=features&newsitems=5&whatfile=crypt )
- */
-
-#ifndef UTIL_CRYPT_H_
-#define UTIL_CRYPT_H_
-
-#include "suricata-common.h"
-
-/* Ratio of output bytes to input bytes for Base64 Encoding is 4:3, hence the
- * required output bytes are 4 * ceil(input_len / 3) and an additional byte
- * for storing the NULL pointer.
- * */
-#define BASE64_BUFFER_SIZE(x) ((4 * ((x) + 2) / 3) + 1)
-
-typedef enum {
- SC_BASE64_OK,
- SC_BASE64_INVALID_ARG,
- SC_BASE64_OVERFLOW,
-
-} CryptId;
-
-int Base64Encode(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen);
-
-#endif /* UTIL_CRYPT_H_ */