]> git.saurik.com Git - apple/xnu.git/blobdiff - EXTERNAL_HEADERS/corecrypto/cchmac.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / cchmac.h
index 81c1ab835a5cff83249e9ba872c2d5ef2830db9f..4493016c8325d85650629ad4e959749d30aed786 100644 (file)
@@ -1,11 +1,12 @@
-/*
- *  cchmac.h
- *  corecrypto
- *
- *  Created on 12/07/2010
- *
- *  Copyright (c) 2010,2011,2012,2014,2015 Apple Inc. All rights reserved.
+/* Copyright (c) (2010,2011,2012,2014,2015,2016,2017,2018,2019) Apple Inc. All rights reserved.
  *
+ * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
+ * is contained in the License.txt file distributed with corecrypto) and only to 
+ * people who accept that license. IMPORTANT:  Any license rights granted to you by 
+ * Apple Inc. (if any) are limited to internal use within your organization only on 
+ * devices and computers you own or control, for the sole purpose of verifying the 
+ * security characteristics and correct functioning of the Apple Software.  You may 
+ * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
  */
 
 #ifndef _CORECRYPTO_CCHMAC_H_
 
 /* An hmac_ctx_t is normally allocated as an array of these. */
 struct cchmac_ctx {
-    uint8_t b[8];
+    uint8_t b[1];
 } CC_ALIGNED(8);
 
-#if CORECRYPTO_USE_TRANSPARENT_UNION
-typedef union {
-    struct cchmac_ctx *hdr;
-    ccdigest_ctx_t digest;
-} cchmac_ctx_t __attribute__((transparent_union));
-#else
 typedef struct cchmac_ctx* cchmac_ctx_t;
-#endif
 
-#define cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE)  (ccdigest_ctx_size(STATE_SIZE, BLOCK_SIZE) + (STATE_SIZE))
+#define cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE) (cc_pad_align(ccdigest_ctx_size(STATE_SIZE, BLOCK_SIZE)) + (STATE_SIZE))
 #define cchmac_di_size(_di_)  (cchmac_ctx_size((_di_)->state_size, (_di_)->block_size))
 
 #define cchmac_ctx_n(STATE_SIZE, BLOCK_SIZE)  ccn_nof_size(cchmac_ctx_size((STATE_SIZE), (BLOCK_SIZE)))
@@ -39,43 +33,25 @@ typedef struct cchmac_ctx* cchmac_ctx_t;
 #define cchmac_di_clear(_di_, _name_) cchmac_ctx_clear((_di_)->state_size, (_di_)->block_size, _name_)
 
 /* Return a ccdigest_ctx_t which can be accesed with the macros in ccdigest.h */
-#if CORECRYPTO_USE_TRANSPARENT_UNION
-#define cchmac_digest_ctx(_di_, HC)    (((cchmac_ctx_t)(HC)).digest)
-#else
 #define cchmac_digest_ctx(_di_, HC)    ((ccdigest_ctx_t)(HC))
-#endif
 
 /* Accesors for ostate fields, this is all cchmac_ctx_t adds to the ccdigest_ctx_t. */
-#if CORECRYPTO_USE_TRANSPARENT_UNION
-#define cchmac_ostate(_di_, HC)    ((struct ccdigest_state *)(((cchmac_ctx_t)(HC)).hdr->b + ccdigest_di_size(_di_)))
-#else
-#define cchmac_ostate(_di_, HC)    ((struct ccdigest_state *)(((cchmac_ctx_t)(HC))->b + ccdigest_di_size(_di_)))
-#endif
+#define cchmac_ostate(_di_, HC)    ((struct ccdigest_state *)(((cchmac_ctx_t)(HC))->b + cc_pad_align(ccdigest_di_size(_di_))))
 #define cchmac_ostate8(_di_, HC)   (ccdigest_u8(cchmac_ostate(_di_, HC)))
 #define cchmac_ostate32(_di_, HC)  (ccdigest_u32(cchmac_ostate(_di_, HC)))
 #define cchmac_ostate64(_di_, HC)  (ccdigest_u64(cchmac_ostate(_di_, HC)))
 #define cchmac_ostateccn(_di_, HC) (ccdigest_ccn(cchmac_ostate(_di_, HC)))
 
 /* Convenience accessors for ccdigest_ctx_t fields. */
-#if CORECRYPTO_USE_TRANSPARENT_UNION
-#define cchmac_istate(_di_, HC)    ccdigest_state(_di_, ((cchmac_ctx_t)(HC)).digest)
-#else
 #define cchmac_istate(_di_, HC)    ccdigest_state(_di_, ((ccdigest_ctx_t)(HC)))
-#endif
 #define cchmac_istate8(_di_, HC)   ccdigest_u8(cchmac_istate(_di_, HC))
 #define cchmac_istate32(_di_, HC)  ccdigest_u32(cchmac_istate(_di_, HC))
 #define cchmac_istate64(_di_, HC)  ccdigest_u64(cchmac_istate(_di_, HC))
 #define cchmac_istateccn(_di_, HC) ccdigest_ccn(cchmac_istate(_di_, HC))
 
-#if CORECRYPTO_USE_TRANSPARENT_UNION
-#define cchmac_data(_di_, HC)      ccdigest_data(_di_, ((cchmac_ctx_t)(HC)).digest)
-#define cchmac_num(_di_, HC)       ccdigest_num(_di_, ((cchmac_ctx_t)(HC)).digest)
-#define cchmac_nbits(_di_, HC)     ccdigest_nbits(_di_, ((cchmac_ctx_t)(HC)).digest)
-#else
 #define cchmac_data(_di_, HC)      ccdigest_data(_di_, ((ccdigest_ctx_t)(HC)))
 #define cchmac_num(_di_, HC)       ccdigest_num(_di_, ((ccdigest_ctx_t)(HC)))
 #define cchmac_nbits(_di_, HC)     ccdigest_nbits(_di_, ((ccdigest_ctx_t)(HC)))
-#endif
 
 void cchmac_init(const struct ccdigest_info *di, cchmac_ctx_t ctx,
                  size_t key_len, const void *key);
@@ -88,20 +64,4 @@ void cchmac(const struct ccdigest_info *di, size_t key_len,
             const void *key, size_t data_len, const void *data,
             unsigned char *mac);
 
-/* Test functions */
-
-struct cchmac_test_input {
-    const struct ccdigest_info *di;
-    size_t key_len;
-    const void *key;
-    size_t data_len;
-    const void *data;
-    size_t mac_len;
-    const void *expected_mac;
-};
-
-int cchmac_test(const struct cchmac_test_input *input);
-int cchmac_test_chunks(const struct cchmac_test_input *input, size_t chunk_size);
-
-
 #endif /* _CORECRYPTO_CCHMAC_H_ */