NaClCrypto.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import <Foundation/Foundation.h>
  21. #define kNaClCryptoPubKeySize 32
  22. #define kNaClCryptoSecKeySize 32
  23. #define kNaClCryptoNonceSize 24
  24. #define kNaClBoxOverhead 16
  25. #define kNaClCryptoSymmKeySize 32
  26. #define kNaClCryptoSymmNonceSize 24
  27. #define kNaClCryptoStreamKeySize 32
  28. #define kNaClCryptoStreamNonceSize 24
  29. @interface NaClCrypto : NSObject
  30. + (NaClCrypto*)sharedCrypto;
  31. - (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey withSeed:(NSData*)seed;
  32. - (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey;
  33. - (NSData*)derivePublicKeyFromSecretKey:(NSData*)secretKey;
  34. - (NSData*)encryptData:(NSData*)plaintext withPublicKey:(NSData*)publicKey signKey:(NSData*)signKey nonce:(NSData*)nonce;
  35. - (NSData*)decryptData:(NSData*)ciphertext withSecretKey:(NSData*)secretKey signKey:(NSData*)signKey nonce:(NSData*)nonce;
  36. - (NSData*)symmetricEncryptData:(NSData*)plaintext withKey:(NSData*)key nonce:(NSData*)nonce;
  37. - (NSData*)symmetricDecryptData:(NSData*)ciphertext withKey:(NSData*)key nonce:(NSData*)nonce;
  38. - (NSData*)streamXorData:(NSData*)data secretKey:(NSData*)secretKey nonce:(NSData*)nonce;
  39. - (NSData*)randomBytes:(int)len;
  40. - (NSData*)zeroBytes:(int)len;
  41. - (void)selfTest;
  42. - (void)longTest;
  43. - (double)benchmark;
  44. @end