summaryrefslogtreecommitdiff
path: root/include/internal
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2022-11-11 16:18:48 +0100
committerTomas Mraz <tomas@openssl.org>2023-02-08 16:20:55 +0100
commit25624c9087d5422c3bb93cd987a066cb7c883a16 (patch)
treeed3b762338f9a08a0fcccfbe09d32f18c5e15bb2 /include/internal
parent416a9286859d444e5a77bbdcc73f0c35b34e574b (diff)
downloadopenssl-new-25624c9087d5422c3bb93cd987a066cb7c883a16.tar.gz
Rationalize FIPS sources
Avoid including QUIC related stuff in the FIPS sources. Also avoid including libssl headers in ssl3_cbc.c. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19658)
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/common.h90
-rw-r--r--include/internal/packet.h132
-rw-r--r--include/internal/packet_quic.h138
-rw-r--r--include/internal/quic_wire.h2
-rw-r--r--include/internal/quic_wire_pkt.h2
-rw-r--r--include/internal/ssl3_cbc.h40
6 files changed, 270 insertions, 134 deletions
diff --git a/include/internal/common.h b/include/internal/common.h
index 83549737ed..dd07e07ab9 100644
--- a/include/internal/common.h
+++ b/include/internal/common.h
@@ -91,6 +91,96 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
# define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
# define HEX_SIZE(type) (sizeof(type)*2)
+# define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
+ l|=(((unsigned long)(*((c)++)))<< 8), \
+ l|=(((unsigned long)(*((c)++)))<<16), \
+ l|=(((unsigned long)(*((c)++)))<<24))
+
+/* NOTE - c is not incremented as per c2l */
+# define c2ln(c,l1,l2,n) { \
+ c+=n; \
+ l1=l2=0; \
+ switch (n) { \
+ case 8: l2 =((unsigned long)(*(--(c))))<<24; \
+ case 7: l2|=((unsigned long)(*(--(c))))<<16; \
+ case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
+ case 5: l2|=((unsigned long)(*(--(c)))); \
+ case 4: l1 =((unsigned long)(*(--(c))))<<24; \
+ case 3: l1|=((unsigned long)(*(--(c))))<<16; \
+ case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
+ case 1: l1|=((unsigned long)(*(--(c)))); \
+ } \
+ }
+
+# define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>24)&0xff))
+
+# define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
+ l|=((unsigned long)(*((c)++)))<<16, \
+ l|=((unsigned long)(*((c)++)))<< 8, \
+ l|=((unsigned long)(*((c)++))))
+
+# define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \
+ l|=((uint64_t)(*((c)++)))<<48, \
+ l|=((uint64_t)(*((c)++)))<<40, \
+ l|=((uint64_t)(*((c)++)))<<32, \
+ l|=((uint64_t)(*((c)++)))<<24, \
+ l|=((uint64_t)(*((c)++)))<<16, \
+ l|=((uint64_t)(*((c)++)))<< 8, \
+ l|=((uint64_t)(*((c)++))))
+
+
+# define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+ *((c)++)=(unsigned char)(((l) )&0xff))
+
+# define l2n6(l,c) (*((c)++)=(unsigned char)(((l)>>40)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>32)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>24)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+ *((c)++)=(unsigned char)(((l) )&0xff))
+
+# define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>48)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>40)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>32)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>24)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+ *((c)++)=(unsigned char)(((l) )&0xff))
+
+/* NOTE - c is not incremented as per l2c */
+# define l2cn(l1,l2,c,n) { \
+ c+=n; \
+ switch (n) { \
+ case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
+ case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
+ case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
+ case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
+ case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
+ case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
+ case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
+ case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
+ } \
+ }
+
+# define n2s(c,s) ((s=(((unsigned int)((c)[0]))<< 8)| \
+ (((unsigned int)((c)[1])) )),(c)+=2)
+# define s2n(s,c) (((c)[0]=(unsigned char)(((s)>> 8)&0xff), \
+ (c)[1]=(unsigned char)(((s) )&0xff)),(c)+=2)
+
+# define n2l3(c,l) ((l =(((unsigned long)((c)[0]))<<16)| \
+ (((unsigned long)((c)[1]))<< 8)| \
+ (((unsigned long)((c)[2])) )),(c)+=3)
+
+# define l2n3(l,c) (((c)[0]=(unsigned char)(((l)>>16)&0xff), \
+ (c)[1]=(unsigned char)(((l)>> 8)&0xff), \
+ (c)[2]=(unsigned char)(((l) )&0xff)),(c)+=3)
+
static ossl_inline int ossl_ends_with_dirsep(const char *path)
{
if (*path != '\0')
diff --git a/include/internal/packet.h b/include/internal/packet.h
index 23e516ebf5..e35281d700 100644
--- a/include/internal/packet.h
+++ b/include/internal/packet.h
@@ -18,7 +18,6 @@
# include <openssl/e_os2.h>
# include "internal/numbers.h"
-# include "internal/quic_vlint.h"
typedef struct {
/* Pointer to where we are currently reading from */
@@ -251,73 +250,6 @@ __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt,
return 1;
}
-# ifndef OPENSSL_NO_QUIC
-
-/*
- * Decodes a QUIC variable-length integer in |pkt| and stores the result in
- * |data|.
- */
-__owur static ossl_inline int PACKET_get_quic_vlint(PACKET *pkt,
- uint64_t *data)
-{
- size_t enclen;
-
- if (PACKET_remaining(pkt) < 1)
- return 0;
-
- enclen = ossl_quic_vlint_decode_len(*pkt->curr);
-
- if (PACKET_remaining(pkt) < enclen)
- return 0;
-
- *data = ossl_quic_vlint_decode_unchecked(pkt->curr);
- packet_forward(pkt, enclen);
- return 1;
-}
-
-/*
- * Decodes a QUIC variable-length integer in |pkt| and stores the result in
- * |data|. Unlike PACKET_get_quic_vlint, this does not advance the current
- * position.
- */
-__owur static ossl_inline int PACKET_peek_quic_vlint(PACKET *pkt,
- uint64_t *data)
-{
- size_t enclen;
-
- if (PACKET_remaining(pkt) < 1)
- return 0;
-
- enclen = ossl_quic_vlint_decode_len(*pkt->curr);
-
- if (PACKET_remaining(pkt) < enclen)
- return 0;
-
- *data = ossl_quic_vlint_decode_unchecked(pkt->curr);
- return 1;
-}
-
-/*
- * Skips over a QUIC variable-length integer in |pkt| without decoding it.
- */
-__owur static ossl_inline int PACKET_skip_quic_vlint(PACKET *pkt)
-{
- size_t enclen;
-
- if (PACKET_remaining(pkt) < 1)
- return 0;
-
- enclen = ossl_quic_vlint_decode_len(*pkt->curr);
-
- if (PACKET_remaining(pkt) < enclen)
- return 0;
-
- packet_forward(pkt, enclen);
- return 1;
-}
-
-# endif
-
/* Equivalent of n2l */
/* Get 4 bytes in network order from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
@@ -695,37 +627,6 @@ __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
return 1;
}
-# ifndef OPENSSL_NO_QUIC
-
-/*
- * Reads a variable-length vector prefixed with a QUIC variable-length integer
- * denoting the length, and stores the contents in |subpkt|. |pkt| can equal
- * |subpkt|. Data is not copied: the |subpkt| packet will share its underlying
- * buffer with the original |pkt|, so data wrapped by |pkt| must outlive the
- * |subpkt|. Upon failure, the original |pkt| and |subpkt| are not modified.
- */
-__owur static ossl_inline int PACKET_get_quic_length_prefixed(PACKET *pkt,
- PACKET *subpkt)
-{
- uint64_t length;
- const unsigned char *data;
- PACKET tmp = *pkt;
-
- if (!PACKET_get_quic_vlint(&tmp, &length) ||
- length > SIZE_MAX ||
- !PACKET_get_bytes(&tmp, &data, (size_t)length)) {
- return 0;
- }
-
- *pkt = tmp;
- subpkt->curr = data;
- subpkt->remaining = (size_t)length;
-
- return 1;
-}
-
-# endif
-
/* Writeable packets */
typedef struct wpacket_sub WPACKET_SUB;
@@ -1035,37 +936,4 @@ int WPACKET_is_null_buf(WPACKET *pkt);
/* Release resources in a WPACKET if a failure has occurred. */
void WPACKET_cleanup(WPACKET *pkt);
-# ifndef OPENSSL_NO_QUIC
-
-/*
- * Starts a QUIC sub-packet headed by a QUIC variable-length integer. A 4-byte
- * representation is used.
- */
-__owur int WPACKET_start_quic_sub_packet(WPACKET *pkt);
-
-/*
- * Starts a QUIC sub-packet headed by a QUIC variable-length integer. max_len
- * specifies the upper bound for the sub-packet size at the time the sub-packet
- * is closed, which determines the encoding size for tthe variable-length
- * integer header. max_len can be a precise figure or a worst-case bound
- * if a precise figure is not available.
- */
-__owur int WPACKET_start_quic_sub_packet_bound(WPACKET *pkt, size_t max_len);
-
-/*
- * Allocates a QUIC sub-packet with exactly len bytes of payload, headed by a
- * QUIC variable-length integer. The pointer to the payload buffer is output and
- * must be filled by the caller. This function assures optimal selection of
- * variable-length integer encoding length.
- */
-__owur int WPACKET_quic_sub_allocate_bytes(WPACKET *pkt, size_t len,
- unsigned char **bytes);
-
-/*
- * Write a QUIC variable-length integer to the packet.
- */
-__owur int WPACKET_quic_write_vlint(WPACKET *pkt, uint64_t v);
-
-# endif
-
#endif /* OSSL_INTERNAL_PACKET_H */
diff --git a/include/internal/packet_quic.h b/include/internal/packet_quic.h
new file mode 100644
index 0000000000..447f75b81f
--- /dev/null
+++ b/include/internal/packet_quic.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#ifndef OSSL_INTERNAL_PACKET_QUIC_H
+# define OSSL_INTERNAL_PACKET_QUIC_H
+# pragma once
+
+# include "internal/packet.h"
+# include "internal/quic_vlint.h"
+
+# ifndef OPENSSL_NO_QUIC
+/*
+ * Decodes a QUIC variable-length integer in |pkt| and stores the result in
+ * |data|.
+ */
+__owur static ossl_inline int PACKET_get_quic_vlint(PACKET *pkt,
+ uint64_t *data)
+{
+ size_t enclen;
+
+ if (PACKET_remaining(pkt) < 1)
+ return 0;
+
+ enclen = ossl_quic_vlint_decode_len(*pkt->curr);
+
+ if (PACKET_remaining(pkt) < enclen)
+ return 0;
+
+ *data = ossl_quic_vlint_decode_unchecked(pkt->curr);
+ packet_forward(pkt, enclen);
+ return 1;
+}
+
+/*
+ * Decodes a QUIC variable-length integer in |pkt| and stores the result in
+ * |data|. Unlike PACKET_get_quic_vlint, this does not advance the current
+ * position.
+ */
+__owur static ossl_inline int PACKET_peek_quic_vlint(PACKET *pkt,
+ uint64_t *data)
+{
+ size_t enclen;
+
+ if (PACKET_remaining(pkt) < 1)
+ return 0;
+
+ enclen = ossl_quic_vlint_decode_len(*pkt->curr);
+
+ if (PACKET_remaining(pkt) < enclen)
+ return 0;
+
+ *data = ossl_quic_vlint_decode_unchecked(pkt->curr);
+ return 1;
+}
+
+/*
+ * Skips over a QUIC variable-length integer in |pkt| without decoding it.
+ */
+__owur static ossl_inline int PACKET_skip_quic_vlint(PACKET *pkt)
+{
+ size_t enclen;
+
+ if (PACKET_remaining(pkt) < 1)
+ return 0;
+
+ enclen = ossl_quic_vlint_decode_len(*pkt->curr);
+
+ if (PACKET_remaining(pkt) < enclen)
+ return 0;
+
+ packet_forward(pkt, enclen);
+ return 1;
+}
+
+/*
+ * Reads a variable-length vector prefixed with a QUIC variable-length integer
+ * denoting the length, and stores the contents in |subpkt|. |pkt| can equal
+ * |subpkt|. Data is not copied: the |subpkt| packet will share its underlying
+ * buffer with the original |pkt|, so data wrapped by |pkt| must outlive the
+ * |subpkt|. Upon failure, the original |pkt| and |subpkt| are not modified.
+ */
+__owur static ossl_inline int PACKET_get_quic_length_prefixed(PACKET *pkt,
+ PACKET *subpkt)
+{
+ uint64_t length;
+ const unsigned char *data;
+ PACKET tmp = *pkt;
+
+ if (!PACKET_get_quic_vlint(&tmp, &length) ||
+ length > SIZE_MAX ||
+ !PACKET_get_bytes(&tmp, &data, (size_t)length)) {
+ return 0;
+ }
+
+ *pkt = tmp;
+ subpkt->curr = data;
+ subpkt->remaining = (size_t)length;
+
+ return 1;
+}
+
+/*
+ * Starts a QUIC sub-packet headed by a QUIC variable-length integer. A 4-byte
+ * representation is used.
+ */
+__owur int WPACKET_start_quic_sub_packet(WPACKET *pkt);
+
+/*
+ * Starts a QUIC sub-packet headed by a QUIC variable-length integer. max_len
+ * specifies the upper bound for the sub-packet size at the time the sub-packet
+ * is closed, which determines the encoding size for tthe variable-length
+ * integer header. max_len can be a precise figure or a worst-case bound
+ * if a precise figure is not available.
+ */
+__owur int WPACKET_start_quic_sub_packet_bound(WPACKET *pkt, size_t max_len);
+
+/*
+ * Allocates a QUIC sub-packet with exactly len bytes of payload, headed by a
+ * QUIC variable-length integer. The pointer to the payload buffer is output and
+ * must be filled by the caller. This function assures optimal selection of
+ * variable-length integer encoding length.
+ */
+__owur int WPACKET_quic_sub_allocate_bytes(WPACKET *pkt, size_t len,
+ unsigned char **bytes);
+
+/*
+ * Write a QUIC variable-length integer to the packet.
+ */
+__owur int WPACKET_quic_write_vlint(WPACKET *pkt, uint64_t v);
+
+# endif /* OPENSSL_NO_QUIC */
+#endif /* OSSL_INTERNAL_PACKET_QUIC_H */
diff --git a/include/internal/quic_wire.h b/include/internal/quic_wire.h
index 005cc8c2a5..a80ab6bbfd 100644
--- a/include/internal/quic_wire.h
+++ b/include/internal/quic_wire.h
@@ -14,7 +14,7 @@
# include "internal/e_os.h"
# include "internal/time.h"
# include "internal/quic_types.h"
-# include "internal/packet.h"
+# include "internal/packet_quic.h"
# ifndef OPENSSL_NO_QUIC
diff --git a/include/internal/quic_wire_pkt.h b/include/internal/quic_wire_pkt.h
index 7abfd46d53..ce3c63057e 100644
--- a/include/internal/quic_wire_pkt.h
+++ b/include/internal/quic_wire_pkt.h
@@ -11,7 +11,7 @@
# define OSSL_QUIC_WIRE_PKT_H
# include <openssl/ssl.h>
-# include "internal/packet.h"
+# include "internal/packet_quic.h"
# include "internal/quic_types.h"
# ifndef OPENSSL_NO_QUIC
diff --git a/include/internal/ssl3_cbc.h b/include/internal/ssl3_cbc.h
new file mode 100644
index 0000000000..3843696ffe
--- /dev/null
+++ b/include/internal/ssl3_cbc.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <openssl/evp.h>
+
+/* tls_pad.c */
+int ssl3_cbc_remove_padding_and_mac(size_t *reclen,
+ size_t origreclen,
+ unsigned char *recdata,
+ unsigned char **mac,
+ int *alloced,
+ size_t block_size, size_t mac_size,
+ OSSL_LIB_CTX *libctx);
+
+int tls1_cbc_remove_padding_and_mac(size_t *reclen,
+ size_t origreclen,
+ unsigned char *recdata,
+ unsigned char **mac,
+ int *alloced,
+ size_t block_size, size_t mac_size,
+ int aead,
+ OSSL_LIB_CTX *libctx);
+
+/* ssl3_cbc.c */
+__owur char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
+__owur int ssl3_cbc_digest_record(const EVP_MD *md,
+ unsigned char *md_out,
+ size_t *md_out_size,
+ const unsigned char *header,
+ const unsigned char *data,
+ size_t data_size,
+ size_t data_plus_mac_plus_padding_size,
+ const unsigned char *mac_secret,
+ size_t mac_secret_length, char is_sslv3);