motify compile link error

motify compile link error
This commit is contained in:
ant 2016-09-18 09:03:25 +08:00
parent 923914edae
commit 03e74a8e50
5418 changed files with 1367914 additions and 206149 deletions

View file

@ -1,121 +1,121 @@
//
// Crypto.swift
// WiGadget
//
// Created by WU JINZHOU on 27/8/15.
// Copyright (c) 2015 WU JINZHOU. All rights reserved.
//
import Foundation
class Crypto {
static var curve25519_private_key = [UInt8]()
static var curve25519_base_point = R.curve25519_base_point
static var curve25519_my_public_key = [UInt8](count: 32, repeatedValue: 0)
static var curve25519_his_public_key = [UInt8]()
static var curve25519_shared_key = [UInt8](count: 32, repeatedValue: 0)
static var aes_128_key = [UInt8]()
static var aes_iv = [UInt8](R.aes_iv.utf8)
static var aes_block_size = aes_iv.count
//generate curve25519 public key
class func makeCurve25519PublicKey() -> String {
for _ in 0 ..< 32 {
curve25519_private_key.append(UInt8(arc4random() % 256))
}
curve25519_donna(&curve25519_my_public_key, &curve25519_private_key, &curve25519_base_point)
return "\(curve25519_my_public_key)"
}
//generate curve25519 shared key & AES shared key
class func makePSK(hisCurve25519PublicKey:String) -> String {
let strArr = hisCurve25519PublicKey.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
curve25519_his_public_key.append(UInt8(intVal))
}
}
curve25519_donna(&curve25519_shared_key, &curve25519_private_key, &curve25519_his_public_key)
aes_128_key = [UInt8](curve25519_shared_key[0...15])
return "\(aes_128_key)"
}
//aes128 encryption
class func encrypt(plainText:String,key:String) -> String {
var k8 = [UInt8]()
let strArr = key.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
k8.append(UInt8(intVal))
}
}
var pt8 = [UInt8](plainText.utf8)
//zero padding
let r = pt8.count % aes_block_size
for _ in 0 ..< (aes_block_size - r) {
pt8.append(0)
}
var ct8 = pt8 //allocate mem for ct8
AES128_CBC_encrypt_buffer(&ct8, &pt8, UInt32(pt8.count), &k8, &aes_iv)
return "\(ct8)"
}
class func decrypt(cipherText:String,key:String) -> String {
var k8 = [UInt8]()
var strArr = key.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
k8.append(UInt8(intVal))
}
}
var ct8 = [UInt8]()
strArr = cipherText.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
ct8.append(UInt8(intVal))
}
}
var pt8 = ct8 //allocate mem for pt8
AES128_CBC_decrypt_buffer(&pt8, &ct8, UInt32(ct8.count), &k8, &aes_iv)
pt8 = pt8.filter({$0 != 0})
let pt = NSString(bytes: pt8, length: pt8.count, encoding: NSUTF8StringEncoding) as! String
return pt
}
}
//
// Crypto.swift
// WiGadget
//
// Created by WU JINZHOU on 27/8/15.
// Copyright (c) 2015 WU JINZHOU. All rights reserved.
//
import Foundation
class Crypto {
static var curve25519_private_key = [UInt8]()
static var curve25519_base_point = R.curve25519_base_point
static var curve25519_my_public_key = [UInt8](count: 32, repeatedValue: 0)
static var curve25519_his_public_key = [UInt8]()
static var curve25519_shared_key = [UInt8](count: 32, repeatedValue: 0)
static var aes_128_key = [UInt8]()
static var aes_iv = [UInt8](R.aes_iv.utf8)
static var aes_block_size = aes_iv.count
//generate curve25519 public key
class func makeCurve25519PublicKey() -> String {
for _ in 0 ..< 32 {
curve25519_private_key.append(UInt8(arc4random() % 256))
}
curve25519_donna(&curve25519_my_public_key, &curve25519_private_key, &curve25519_base_point)
return "\(curve25519_my_public_key)"
}
//generate curve25519 shared key & AES shared key
class func makePSK(hisCurve25519PublicKey:String) -> String {
let strArr = hisCurve25519PublicKey.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
curve25519_his_public_key.append(UInt8(intVal))
}
}
curve25519_donna(&curve25519_shared_key, &curve25519_private_key, &curve25519_his_public_key)
aes_128_key = [UInt8](curve25519_shared_key[0...15])
return "\(aes_128_key)"
}
//aes128 encryption
class func encrypt(plainText:String,key:String) -> String {
var k8 = [UInt8]()
let strArr = key.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
k8.append(UInt8(intVal))
}
}
var pt8 = [UInt8](plainText.utf8)
//zero padding
let r = pt8.count % aes_block_size
for _ in 0 ..< (aes_block_size - r) {
pt8.append(0)
}
var ct8 = pt8 //allocate mem for ct8
AES128_CBC_encrypt_buffer(&ct8, &pt8, UInt32(pt8.count), &k8, &aes_iv)
return "\(ct8)"
}
class func decrypt(cipherText:String,key:String) -> String {
var k8 = [UInt8]()
var strArr = key.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
k8.append(UInt8(intVal))
}
}
var ct8 = [UInt8]()
strArr = cipherText.characters.split { $0 == "," }.map { String($0) }
for item in strArr {
let components = item.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let part = components.joinWithSeparator("")
if let intVal = Int(part) {
ct8.append(UInt8(intVal))
}
}
var pt8 = ct8 //allocate mem for pt8
AES128_CBC_decrypt_buffer(&pt8, &ct8, UInt32(ct8.count), &k8, &aes_iv)
pt8 = pt8.filter({$0 != 0})
let pt = NSString(bytes: pt8, length: pt8.count, encoding: NSUTF8StringEncoding) as! String
return pt
}
}

View file

@ -1,14 +1,14 @@
#ifndef __curve25519_donnaDotH__
#define __curve25519_donnaDotH__
#ifdef __cplusplus
extern "C" {
#endif
void curve25519_donna( unsigned char *outKey, const unsigned char *inSecret, const unsigned char *inBasePoint );
#ifdef __cplusplus
}
#endif
#endif // __curve25519_donnaDotH__
#ifndef __curve25519_donnaDotH__
#define __curve25519_donnaDotH__
#ifdef __cplusplus
extern "C" {
#endif
void curve25519_donna( unsigned char *outKey, const unsigned char *inSecret, const unsigned char *inBasePoint );
#ifdef __cplusplus
}
#endif
#endif // __curve25519_donnaDotH__

File diff suppressed because it is too large Load diff

View file

@ -1,40 +1,40 @@
#ifndef _AES_H_
#define _AES_H_
#include <stdint.h>
// #define the macros below to 1/0 to enable/disable the mode of operation.
//
// CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding.
// ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously.
// The #ifndef-guard allows it to be configured before #include'ing or at compile time.
#ifndef CBC
#define CBC 1
#endif
#ifndef ECB
#define ECB 1
#endif
#if defined(ECB) && ECB
void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t *output);
void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output);
#endif // #if defined(ECB) && ECB
#if defined(CBC) && CBC
void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
#endif // #if defined(CBC) && CBC
#endif //_AES_H_
#ifndef _AES_H_
#define _AES_H_
#include <stdint.h>
// #define the macros below to 1/0 to enable/disable the mode of operation.
//
// CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding.
// ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously.
// The #ifndef-guard allows it to be configured before #include'ing or at compile time.
#ifndef CBC
#define CBC 1
#endif
#ifndef ECB
#define ECB 1
#endif
#if defined(ECB) && ECB
void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t *output);
void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output);
#endif // #if defined(ECB) && ECB
#if defined(CBC) && CBC
void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
#endif // #if defined(CBC) && CBC
#endif //_AES_H_