Package: jihyocrypt
IntroductionInstallationOptionsAll functionsOptional ArgumentsPassphraseInjecting Key Generation ParametersStructure of the OutputSpeed TestsCreditsLicenseBugsJihyocryptA simple, standalone library-based implementation ofSalsa20 stream cipherdeveloped byDaniel J Bernsteinto encrypt and decrypt data along with a password determined key function.Includes a multi-round nonce+password based key and hash function. The program is determined to be fairly cryptographically secure and is sufficiently fast for its implementation needs.It implements a memory buffer for file encryptions and decryptions to make sure the memory usage does not blow up.From the speed tests it can be asserted that it requires ~6s to encrypt 1GB of data. Which is fairly fast for most encryption/decryption operations required in Microservices and standalone applications(the main target for this).A rust based library with equivalent API is soon underway.InstallationInstalling fromPyPIpython3 -m pip install jihyocryptOr install from sourcegit clone https://gitlab.com/loggerheads-with-binary/jihyocrypt
cd jihyocrypt 
python3 -m pip install -r requirements.txt 
python3 -m setup.py installOptionsThe following functions exposed for different purposes. The following mnemonic has been used for the encryption and decryption.Syntax for functions::syntax: enc/dec_x2xwhere x: s -> Pickleable object; f-> File ; b -> bytestringenc/dec :enc-> Encryption , dec -> Decryptionexample: enc_s2f means encrypt from a standard object to a fileEx:importjihyocryptasjihyojihyo.enc_f2f('plaintext.txt',output_file='ciphertext.bin',password=passphrase)#Returns None, ciphertext.bin consists of encrypted dataOptional ArgumentsThe exposed encryption and decryption functions consist of two flags:FlagDefaultIf TrueIf Falseprogress_barFalsePrints a progress bar to stderr which can be used to monitor the  progress of encryption/decryptionNo such bar  is producedredundantTrueEncodes the hash of the nonce and  passphrase inside the outputAdvisable to use since incorrect  decryption will be flagged by  the programThe hash is not outputted.During decryption with incorrect passphrase,the program will  generate incorrect output flagging  no error.It also consists of an optionalbuffer_sizeargument in functions involving a file intermediary. The buffer size can be changed and is by default 3MB. A sweet spot for larger files withrespect to timeis ~100MB. The choice of time vs memory footprint is left to the developerPassphrasePassphrase can be a string/bytestring of any length. The phrase is put through a key generation function along with a nonce which generates a 256 bit key for the Salsa20 cipher and a 512 bit hash for the password verification.If the redundant flag is set to False, the hash is not generated at all while if it is True, the hash is encoded in the output.Note: Theredundantflag should be the same in both encryption and decryption. Otherwise it can lead to erroneous output/DecryptionErrorInjecting Key Generation ParametersThe program uses two different integers,DEFAULT_OBFUSCATION_ROUNDSandDEFAULT_JPIC_ROUNDS(JPIC is the 512 bit hash and is short for Jihyocrypt Password Integrity Check)FlagDefaultRecommendedPurposeDEFAULT_OBFUSCATION_ROUNDS6>4To create a suitable 256 bit key for Salsa20 cipher from provided  password and nonceDEFAULT_JPIC_ROUNDS6>2To create a suitable 512 bit hash to verify validity of input password  during decryptionThe following parameters can be modified for modifying the key generation process. A higher value of theDEFAULT_OBFUSCATION_ROUNDSwill increase security of the key generated from a simple passphrase, butalso increase the time needed. Similarly, a higher value ofDEFAULT_JPIC_ROUNDSwill reduce the chances of backtracking an encryption password butrequire more time.Injection can be done as follows:importjihyocryptasjihyojihyo.DEFAULT_OBFUSCATION_ROUNDS=N#N>0, N : intjihyo.DEFAULT_JPIC_ROUNDS=M#M>0, M : int##Encryption/Decryption values must be sameNote that if injection is used, injection values should be same for both encryption and decryptionStructure of The outputLet's assume the plaintext input is a bytestring of N bytes, the following is the output structureIfredundant == TrueCiphertext Size = N + 72-------------------|---------------------------------|---------------------------------8 (nonce)64 (JPIC)N (encrypted ciphertext)Ifredundant == FalseCiphertext Size = N + 8-------------------|---------------------------------------------------8 (nonce)N (encrypted ciphertext)Speed Tests:The following speed tests were performed using aGoogle Colab Scriptand Google Colab Resources. Your results may vary significantly.The following tests were performedKey Generation vs No of RoundsJPIC Generation vs No of RoundsPlaintext Encryption and Decryption (b2b) vs sizeFile to File Encryption and Decryption (f2f( vs sizePlaintext Encryption (f2f) based on buffer sizeKey Generation vs No of Rounds:As expected, the behavior is fairly linear with O(N) complexity.JPIC Generation vs No of Rounds:This behavior is fairly linear as well, and is ~(O(N)redundant=True- O(N)redundant=False)Plaintext Encryption (b2b) vs sizeStandard linear behavior as expected.File to File Encryption vs sizeSimilar behavior with added overhead of File I/O. Takes about 12.8 secs to encrypt a 1 GB, this can vary with disk I/O speeds.Plaintext Encryption (f2f) based on buffer sizeA weird trend I noticed is the drop and then rise in time needed for encryption alongwith increase in buffer size. In my experience, a buffer of about 100MB can significantly reduce time. While above, it starts becoming slower. I don't have a possible explanation for this.Then why is the JihyoCrypt buffer defaulting to 3MB one could ask. It's because when I first developed it, memory was a larger concern than Speed. The program is regularly used to encrypt and decrypt large files(20 GB and above), and the time difference is not significant. However, having only ~6 MB of the memory being occupied vs ~100 MB of the memory being occupied for an hour or more is a choice left to the programmer. As mentioned before, one can easily change the buffer size since it is just a parameter of the encryption/decryption.Credits:Credits for the following libraries used:pycryptodomeAnd credits toDaniel J Bernsteinfor theSalsa20 stream cipherLicenseThe library is provided withMIT LicenseBugsAny bugs or cryptographic improvements can be suggested todev@aniruddh.ml