123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- /*##############################################################################
- ## HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®. All rights reserved.
- ############################################################################## */
- EXPORT Crypto := MODULE
- IMPORT lib_cryptolib;
- /**
- * Returns set of supported Hash Algorithms
- *
- * @return SET OF STRING containing all supported Hash Algorithms
- */
- EXPORT SET OF STRING SupportedHashAlgorithms() := lib_cryptolib.CryptoLib.SupportedHashAlgorithms();
- /**
- * Returns set of supported CipherAlgorithms
- *
- * @return SET OF STRING containing all supported Cipher Algorithms
- */
- EXPORT SET OF STRING SupportedSymmetricCipherAlgorithms() := lib_cryptolib.CryptoLib.SupportedSymmetricCipherAlgorithms();
- /**
- * Returns set of supported Public Key Algorithms
- *
- * @return SET OF STRING containing all supported Public Key Algorithms
- */
- EXPORT SET OF STRING SupportedPublicKeyAlgorithms() := lib_cryptolib.CryptoLib.SupportedPublicKeyAlgorithms();
- /**
- * Hashing module containing all the supported hashing functions.
- *
- * @param hashAlgorithm The Hashing algorithm to use, as returned by SupportedHashAlgorithms()
- */
- EXPORT Hashing(VARSTRING hashAlgorithm) := MODULE
- /**
- * Create a hash of the given data, using a hash algorithm that
- * was returned by SupportedHashAlgorithms()
- *
- * @param inputData Data to hash
- * @return Hashed contents
- */
- EXPORT DATA Hash(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.Hash(hashAlgorithm, inputData);
- END;
- END; // Hashing module
- //-----
- /**
- * Encryption module containing all symmetric encryption/decryption functions
- *
- * @param algorithm Symmetric algorithm to use, as returned by SupportedSymmetricCipherAlgorithms()
- * @param passphrase Passphrase string to use for encryption/encryption
- */
- EXPORT SymmetricEncryption(VARSTRING algorithm, VARSTRING passphrase) := MODULE
- /**
- * Encrypt the given data, using the specified passphrase and symmetric cipher
- * algorithm that was returned by SupportedSymmetricCipherAlgorithms()
- *
- * @param inputData Contents to encrypt
- * @return Encrypted cipher
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SymmetricEncrypt( algorithm, passphrase, inputData );
- END;
-
- /**
- * Decrypt the given cipher, using the specified passphrase and symmetric cipher
- * algorithm that was returned by SupportedSymmetricCipherAlgorithms()
- *
- * @param encryptedData Contents to decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SymmetricDecrypt( algorithm, passphrase, encryptedData );
- END;
- END; // SymmetricEncryption module
- /**
- * Encryption module containing symmetric encryption/decryption functions
- *
- * @param algorithm Symmetric algorithm to use, as returned by SupportedSymmetricCipherAlgorithms()
- * @param passphrase Passphrase to use for encryption/encryption
- */
- EXPORT SymmEncryption(VARSTRING algorithm, DATA passphrase) := MODULE
- /**
- * Encrypt the given data, using the specified passphrase and symmetric cipher
- * algorithm that was returned by SupportedSymmetricCipherAlgorithms()
- *
- * @param inputData Contents to encrypt
- * @return Encrypted cipher
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SymEncrypt( algorithm, passphrase, inputData );
- END;
- /**
- * Decrypt the given cipher, using the specified passphrase and symmetric cipher
- * algorithm that was returned by SupportedSymmetricCipherAlgorithms()
- *
- * @param encryptedData Contents to decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SymDecrypt( algorithm, passphrase, encryptedData );
- END;
- END; // SymmEncryption module
- /**
- * Encryption module containing asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm ASymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyFile File specification of PEM formatted public key file
- * @param privateKeyFile File specification of PEM formatted private key file
- * @param passphrase Passphrase string to use for encryption/encryption/signing/verifying
- */
- EXPORT PublicKeyEncryption(VARSTRING pkAlgorithm, VARSTRING publicKeyFile = '', VARSTRING privateKeyFile = '', VARSTRING passphrase = '') := MODULE
- /**
- * Encrypt the given data, using the specified public key file,
- * passphrase, and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.Encrypt( pkAlgorithm, publicKeyFile, passphrase, inputData);
- END;
- /**
- * Decrypt the given encrypted data, using the specified private key file,
- * passphrase, and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.Decrypt( pkAlgorithm, privateKeyFile, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the
- * specified private key file, passphrase and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed Digital signature
- */
- EXPORT DATA Sign( DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.Sign( pkAlgorithm, privateKeyFile, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using
- * the specified public key file, passphrase and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Boolean TRUE/FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.VerifySignature( pkAlgorithm, publicKeyFile, passphrase, signature, signedData);
- END;
- END; // PublicKeyEncryption module
- /**
- * Encryption module containing asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm ASymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyFile File specification of PEM formatted public key file
- * @param privateKeyFile File specification of PEM formatted private key file
- * @param passphrase Passphrase to use for encryption/decryption/signing/verifying
- */
- EXPORT PKEncryption(VARSTRING pkAlgorithm, VARSTRING publicKeyFile = '', VARSTRING privateKeyFile = '', DATA passphrase = D'') := MODULE
- /**
- * Encrypt the given data, using the specified public key file,
- * passphrase, and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKEncrypt( pkAlgorithm, publicKeyFile, passphrase, inputData);
- END;
- /**
- * Decrypt the given encrypted data, using the specified private key file,
- * passphrase, and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKDecrypt( pkAlgorithm, privateKeyFile, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the
- * specified private key file, passphrase and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed Digital signature
- */
- EXPORT DATA Sign( DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKSign( pkAlgorithm, privateKeyFile, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using
- * the specified public key file, passphrase and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Boolean TRUE/FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKVerifySignature( pkAlgorithm, publicKeyFile, passphrase, signature, signedData);
- END;
- END; // PKEncryption module
- /**
- * Encryption module containing asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm Asymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyLFN LFN specification of PEM formatted public key file
- * @param privateKeyLFN LFN specification of PEM formatted private key file
- * @param passphrase Passphrase string to use for encryption/encryption/signing/verifying
- */
- EXPORT PublicKeyEncryptionFromLFN(VARSTRING pkAlgorithm, VARSTRING publicKeyLFN = '', VARSTRING privateKeyLFN = '', VARSTRING passphrase = '') := MODULE
- /**
- * Encrypt the given data, using the specified public key LFN,
- * passphrase, and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.EncryptLFN( pkAlgorithm, publicKeyLFN, passphrase, inputData);
- END;
- /**
- * Decrypt the given encrypted data, using the specified private key LFN,
- * passphrase, and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.DecryptLFN( pkAlgorithm, privateKeyLFN, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the
- * specified private key LFN, passphrase and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed Digital signature
- */
- EXPORT DATA Sign( DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SignLFN( pkAlgorithm, privateKeyLFN, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using
- * the specified public key LFN, passphrase and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Boolean TRUE/FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.VerifySignatureLFN( pkAlgorithm, publicKeyLFN, passphrase, signature, signedData);
- END;
- END; // PublicKeyEncryptionFromLFN module
- /**
- * Encryption module containing asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm Asymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyLFN LFN specification of PEM formatted public key file
- * @param privateKeyLFN LFN specification of PEM formatted private key file
- * @param passphrase Passphrase to use for encryption/encryption/signing/verifying
- */
- EXPORT PKEncryptionFromLFN(VARSTRING pkAlgorithm, VARSTRING publicKeyLFN = '', VARSTRING privateKeyLFN = '', DATA passphrase = D'') := MODULE
- /**
- * Encrypt the given data, using the specified public key LFN,
- * passphrase, and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKEncryptLFN( pkAlgorithm, publicKeyLFN, passphrase, inputData);
- END;
- /**
- * Decrypt the given encrypted data, using the specified private key LFN,
- * passphrase, and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKDecryptLFN( pkAlgorithm, privateKeyLFN, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the
- * specified private key LFN, passphrase and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed Digital signature
- */
- EXPORT DATA Sign( DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKSignLFN( pkAlgorithm, privateKeyLFN, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using
- * the specified public key LFN, passphrase and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Boolean TRUE/FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKVerifySignatureLFN( pkAlgorithm, publicKeyLFN, passphrase, signature, signedData);
- END;
- END; // PKEncryptionFromLFN module
- /**
- * Encryption module containing all asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm ASymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyBuff PEM formatted Public key buffer
- * @param privateKeyBuff PEM formatted Private key buffer
- * @param passphrase Passphrase string to use for encryption/encryption/signing/verifying
- */
- EXPORT PublicKeyEncryptionFromBuffer(VARSTRING pkAlgorithm, VARSTRING publicKeyBuff = '', VARSTRING privateKeyBuff = '', VARSTRING passphrase = '') := MODULE
- /**
- * Encrypt the given data, using the specified public key, passphrase,
- * and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.EncryptBuff( pkAlgorithm, publicKeyBuff, passphrase, inputData);
- END;
-
- /**
- * Decrypt the given data, using the specified private key, passphrase,
- * and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.DecryptBuff(pkAlgorithm, privateKeyBuff, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the specified private key,
- * passphrase, and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed digital signature
- */
- EXPORT DATA Sign(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.SignBuff( pkAlgorithm, privateKeyBuff, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using the specified public key,
- * passphrase, and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Booolean TRUE if signature is valid, otherwise FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.VerifySignatureBuff( pkAlgorithm, publicKeyBuff, passphrase, signature, signedData);
- END;
-
- END; // PublicKeyEncryptionFromBuffer module
- /**
- * Encryption module containing asymmetric encryption/decryption/digital
- * signing/signature verification functions
- *
- * @param pkAlgorithm ASymmetric algorithm to use, as returned by SupportedPublicKeyAlgorithms()
- * @param publicKeyBuff PEM formatted Public key buffer
- * @param privateKeyBuff PEM formatted Private key buffer
- * @param passphrase Passphrase to use for encryption/encryption/signing/verifying
- */
- EXPORT PKEncryptionFromBuffer(VARSTRING pkAlgorithm, VARSTRING publicKeyBuff = '', VARSTRING privateKeyBuff = '', DATA passphrase = D'') := MODULE
- /**
- * Encrypt the given data, using the specified public key, passphrase,
- * and algorithm
- *
- * @param inputData Contents to Encrypt
- * @return Encrypted data
- */
- EXPORT DATA Encrypt(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKEncryptBuff( pkAlgorithm, publicKeyBuff, passphrase, inputData);
- END;
- /**
- * Decrypt the given data, using the specified private key, passphrase,
- * and algorithm
- *
- * @param encryptedData Contents to Decrypt
- * @return Decrypted data
- */
- EXPORT DATA Decrypt(DATA encryptedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKDecryptBuff(pkAlgorithm, privateKeyBuff, passphrase, encryptedData);
- END;
- /**
- * Create a digital signature of the given data, using the specified private key,
- * passphrase, and algorithm
- *
- * @param inputData Contents to sign
- * @return Computed digital signature
- */
- EXPORT DATA Sign(DATA inputData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKSignBuff( pkAlgorithm, privateKeyBuff, passphrase, inputData);
- END;
- /**
- * Verify the given digital signature of the given data, using the specified public key,
- * passphrase, and algorithm
- *
- * @param signature Signature to verify
- * @param signedData Data used to create signature
- * @return Booolean TRUE if signature is valid, otherwise FALSE
- */
- EXPORT BOOLEAN VerifySignature(DATA signature, DATA signedData) := FUNCTION
- RETURN lib_cryptolib.CryptoLib.PKVerifySignatureBuff( pkAlgorithm, publicKeyBuff, passphrase, signature, signedData);
- END;
- END; //PKEncryptionFromBuffer module
- END; // Crypto module
|