]> git.saurik.com Git - apple/xnu.git/blobdiff - EXTERNAL_HEADERS/corecrypto/ccmode_impl.h
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / ccmode_impl.h
index 1337e146710cc177867e18f3e5ea00c40fbb77e6..849881ed49d74e4b9ab8ec1427e263055e6c2d3d 100644 (file)
@@ -1,11 +1,12 @@
-/*
- *  ccmode_impl.h
- *  corecrypto
- *
- *  Created on 12/07/2010
- *
- *  Copyright (c) 2012,2015 Apple Inc. All rights reserved.
+/* Copyright (c) (2010,2011,2012,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_CCMODE_IMPL_H_
@@ -25,6 +26,7 @@ struct ccmode_ecb {
                 size_t key_nbytes, const void *key);
     int (*ecb)(const ccecb_ctx *ctx, size_t nblocks, const void *in,
                void *out);
+    void (*roundkey)(const ccecb_ctx *ctx, unsigned r, void *key);
 };
 
 /*!
@@ -35,7 +37,7 @@ struct ccmode_ecb {
  *   1- ccmod_xxx_init()
  *   2- ccmod_xxx_decrypt()
  *   3- ccmod_xxx_encrypt()
- * 
+ *
  * stateful modes CCM and GCM: They provide 7 interface functions that return error codes if a function is called out of state
  *   1- ccmod_xxx_init()
  *   2- ccmod_xxx_setiv()
@@ -101,9 +103,11 @@ cc_aligned_struct(16) ccctr_ctx;
 
 struct ccmode_ctr {
     size_t size;        /* first argument to ccctr_ctx_decl(). */
-    size_t block_size;
-    int (*init)(const struct ccmode_ctr *ctr, ccctr_ctx *ctx,
+    size_t block_size;  /* for historical reasons, this is set to 1 */
+    size_t ecb_block_size;  /* the actual block size of the underlying cipher */
+    int (*init)(const struct ccmode_ctr *mode, ccctr_ctx *ctx,
                 size_t key_len, const void *key, const void *iv);
+    int (*setctr)(const struct ccmode_ctr *mode, ccctr_ctx *ctx, const void *ctr);
     int (*ctr)(ccctr_ctx *ctx, size_t nbytes, const void *in, void *out);
     const void *custom;
 };
@@ -125,21 +129,19 @@ cc_aligned_struct(16) ccxts_ctx;
 cc_aligned_struct(16) ccxts_tweak;
 
 struct ccmode_xts {
-    size_t size;        /* first argument to ccxts_ctx_decl(). */
-    size_t tweak_size;  /* first argument to ccxts_tweak_decl(). */
+    size_t size;        /* first argument to ccxts_ctx_decl(). Size of the ctx data structure */
+    size_t tweak_size;  /* first argument to ccxts_tweak_decl(). Size of the tweak structure, not the expected tweak size */
     size_t block_size;
 
-    /* Create a xts key from a xts mode object.  The tweak_len here
-     determines how long the tweak is in bytes, for each subsequent call to
-     ccmode_xts->xts().
-     key must point to at least 'size' cc_units of free storage.
-     tweak_key must point to at least 'tweak_size' cc_units of free storage.
+    /* Create a xts key from a xts mode object.
+     key must point to at least 'size' bytes of free storage.
+     tweak_key must point to at least 'tweak_size' bytes of free storage.
      key and tweak_key must differ.
      Returns nonzero on failure.
      */
     int (*init)(const struct ccmode_xts *xts, ccxts_ctx *ctx,
                 size_t key_nbytes, const void *data_key, const void *tweak_key);
-    
+
     void (*key_sched)(const struct ccmode_xts *xts, ccxts_ctx *ctx,
                       size_t key_nbytes, const void *data_key, const void *tweak_key);
 
@@ -174,7 +176,7 @@ struct ccmode_gcm {
     const void *custom;
 };
 
-//8- GCM mode, statful
+//8- CCM mode, stateful
 cc_aligned_struct(16) ccccm_ctx;
 cc_aligned_struct(16) ccccm_nonce;
 
@@ -193,6 +195,20 @@ struct ccmode_ccm {
     const void *custom;
 };
 
+/* We need to expose this (currently)to keep CommonCrypto happy. */
+struct _ccmode_ccm_nonce {
+    unsigned char A_i[16];      /* crypto block iv */
+    unsigned char B_i[16];      /* mac block iv */
+    unsigned char MAC[16];      /* crypted mac */
+    unsigned char buf[16];      /* crypt buffer */
+
+    uint32_t mode;         /* mode: IV -> AD -> DATA */
+    uint32_t buflen;       /* length of data in buf */
+    uint32_t b_i_len;      /* length of cbcmac data in B_i */
+
+    size_t nonce_size;
+    size_t mac_size;
+};
 
 /* OMAC mode. */
 cc_aligned_struct(16) ccomac_ctx;