aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-19 17:13:32 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-19 17:23:39 -0600
commit6665922672948a45ce5d306458660ef094b37007 (patch)
treea98c824b82da86a5fdfec42703acda51ece2d3bd
parent83a299c450260e895ab7e3a0a4d4e0a44a8ece31 (diff)
downloadcryptography-6665922672948a45ce5d306458660ef094b37007.tar.gz
cryptography-6665922672948a45ce5d306458660ef094b37007.tar.bz2
cryptography-6665922672948a45ce5d306458660ef094b37007.zip
add cipher bindings for CommonCrypto
-rw-r--r--cryptography/hazmat/bindings/commoncrypto/binding.py1
-rw-r--r--cryptography/hazmat/bindings/commoncrypto/common_cryptor.py131
2 files changed, 132 insertions, 0 deletions
diff --git a/cryptography/hazmat/bindings/commoncrypto/binding.py b/cryptography/hazmat/bindings/commoncrypto/binding.py
index 9c1af40a..a5a0dca8 100644
--- a/cryptography/hazmat/bindings/commoncrypto/binding.py
+++ b/cryptography/hazmat/bindings/commoncrypto/binding.py
@@ -26,6 +26,7 @@ class Binding(object):
_modules = [
"common_digest",
"common_hmac",
+ "common_cryptor",
]
ffi = None
diff --git a/cryptography/hazmat/bindings/commoncrypto/common_cryptor.py b/cryptography/hazmat/bindings/commoncrypto/common_cryptor.py
new file mode 100644
index 00000000..69edf1e7
--- /dev/null
+++ b/cryptography/hazmat/bindings/commoncrypto/common_cryptor.py
@@ -0,0 +1,131 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+INCLUDES = """
+#include <CommonCrypto/CommonCryptor.h>
+"""
+
+TYPES = """
+enum {
+ kCCAlgorithmAES128 = 0,
+ kCCAlgorithmDES,
+ kCCAlgorithm3DES,
+ kCCAlgorithmCAST,
+ kCCAlgorithmRC4,
+ kCCAlgorithmRC2,
+ kCCAlgorithmBlowfish
+};
+typedef uint32_t CCAlgorithm;
+enum {
+ kCCSuccess = 0,
+ kCCParamError = -4300,
+ kCCBufferTooSmall = -4301,
+ kCCMemoryFailure = -4302,
+ kCCAlignmentError = -4303,
+ kCCDecodeError = -4304,
+ kCCUnimplemented = -4305
+};
+typedef int32_t CCCryptorStatus;
+typedef uint32_t CCOptions;
+enum {
+ kCCEncrypt = 0,
+ kCCDecrypt,
+};
+typedef uint32_t CCOperation;
+typedef ... *CCCryptorRef;
+
+enum {
+ kCCModeOptionCTR_LE = 0x0001,
+ kCCModeOptionCTR_BE = 0x0002
+};
+
+typedef uint32_t CCModeOptions;
+
+enum {
+ kCCModeECB = 1,
+ kCCModeCBC = 2,
+ kCCModeCFB = 3,
+ kCCModeCTR = 4,
+ kCCModeF8 = 5, // Unimplemented for now (not included)
+ kCCModeLRW = 6, // Unimplemented for now (not included)
+ kCCModeOFB = 7,
+ kCCModeXTS = 8,
+ kCCModeRC4 = 9,
+ kCCModeCFB8 = 10,
+};
+typedef uint32_t CCMode;
+enum {
+ ccNoPadding = 0,
+ ccPKCS7Padding = 1,
+};
+typedef uint32_t CCPadding;
+"""
+
+FUNCTIONS = """
+CCCryptorStatus CCCryptorCreateWithMode(
+ CCOperation, /* kCCEncrypt, kCCEncrypt */
+ CCMode,
+ CCAlgorithm,
+ CCPadding,
+ const void *, /* optional initialization vector */
+ const void *, /* raw key material */
+ size_t,
+ const void *, /* raw tweak material */
+ size_t,
+ int, /* number of rounds. 0 == default */
+ CCModeOptions,
+ CCCryptorRef *); /* RETURNED */
+
+CCCryptorStatus CCCryptorCreate(
+ CCOperation, /* kCCEncrypt, etc. */
+ CCAlgorithm, /* kCCAlgorithmDES, etc. */
+ CCOptions, /* kCCOptionPKCS7Padding, etc. */
+ const void *, /* raw key material */
+ size_t,
+ const void *, /* optional initialization vector */
+ CCCryptorRef *); /* RETURNED */
+CCCryptorStatus CCCryptorUpdate(
+ CCCryptorRef,
+ const void *,
+ size_t,
+ void *, /* data RETURNED here */
+ size_t,
+ size_t *); /* number of bytes written */
+CCCryptorStatus CCCryptorFinal(
+ CCCryptorRef,
+ void *,
+ size_t,
+ size_t *); /* number of bytes written */
+CCCryptorStatus CCCryptorRelease(CCCryptorRef);
+
+/* GCM functions, 10.8+ iOS 5+ */
+enum {
+ kCCModeGCM = 11
+};
+CCCryptorStatus CCCryptorGCMAddIV(CCCryptorRef, const void *, size_t);
+CCCryptorStatus CCCryptorGCMAddAAD(CCCryptorRef, const void *, size_t);
+CCCryptorStatus CCCryptorGCMEncrypt(CCCryptorRef, const void *, size_t,
+ void *);
+CCCryptorStatus CCCryptorGCMDecrypt(CCCryptorRef, const void *, size_t,
+ void *);
+CCCryptorStatus CCCryptorGCMFinal(CCCryptorRef, const void *, size_t *);
+CCCryptorStatus CCCryptorGCMReset(CCCryptorRef);
+"""
+
+MACROS = """
+"""
+
+CUSTOMIZATIONS = """
+"""
+
+CONDITIONAL_NAMES = {}