Kaynağa Gözat

README update with AES cipher

Marcin Krzyżanowski 10 yıl önce
ebeveyn
işleme
6e7f8241bf
3 değiştirilmiş dosya ile 14 ekleme ve 2 silme
  1. 12 1
      CryptoSwift/AES.swift
  2. 1 1
      CryptoSwiftTests/CipherTests.swift
  3. 1 0
      README.md

+ 12 - 1
CryptoSwift/AES.swift

@@ -107,8 +107,19 @@ public class AES {
             return nil;
             return nil;
         }
         }
     }
     }
+    
+    class public func blockSizeBytes() -> Int {
+        return 128 / 8
+    }
+        
+    public func encrypt(message:NSData) -> NSData? {
+        
+        if (message.length > AES.blockSizeBytes()) {
+            // 128 bit block exceeded
+            println("AES 128-bit block exceeded!");
+            return nil;
+        }
         
         
-    public func encrypt(message:NSData) -> NSData {
         let input = message.bytes()
         let input = message.bytes()
         let expandedKey = expandKey()
         let expandedKey = expandKey()
         
         

+ 1 - 1
CryptoSwiftTests/CipherTests.swift

@@ -48,7 +48,7 @@ class CipherTests: XCTestCase {
         
         
         if let aes = AES(key: NSData.withBytes(aesKey)) {
         if let aes = AES(key: NSData.withBytes(aesKey)) {
             let encrypted = aes.encrypt(NSData.withBytes(input))
             let encrypted = aes.encrypt(NSData.withBytes(input))
-            XCTAssertEqual(encrypted, NSData.withBytes(expected), "encryption failed")
+            XCTAssertEqual(encrypted!, NSData.withBytes(expected), "encryption failed")
         } else {
         } else {
             XCTAssert(false, "failed")
             XCTAssert(false, "failed")
         }
         }

+ 1 - 0
README.md

@@ -21,6 +21,7 @@ Good mood
 - [CRC32](http://en.wikipedia.org/wiki/Cyclic_redundancy_check) (well, kind of hash)
 - [CRC32](http://en.wikipedia.org/wiki/Cyclic_redundancy_check) (well, kind of hash)
 
 
 #####Cipher
 #####Cipher
+- [AES-128, AES-192, AES-256](http://csrc.nist.gov/publications/fips/fips197/fips-197.pd8) with 128-bit block (caution: encryption only for now)
 - [ChaCha20](http://cr.yp.to/chacha/chacha-20080128.pdf)
 - [ChaCha20](http://cr.yp.to/chacha/chacha-20080128.pdf)
 
 
 #####Message authenticators
 #####Message authenticators