<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openssl.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Drankinatty</id>
	<title>OpenSSLWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openssl.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Drankinatty"/>
	<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php/Special:Contributions/Drankinatty"/>
	<updated>2026-04-11T16:24:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Talk:Random_Numbers&amp;diff=2435</id>
		<title>Talk:Random Numbers</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Talk:Random_Numbers&amp;diff=2435"/>
		<updated>2016-07-11T21:57:29Z</updated>

		<summary type="html">&lt;p&gt;Drankinatty: /* Should we be promoting a commercial company? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Is RAND_poll part of the public API?==&lt;br /&gt;
&lt;br /&gt;
I have removed the question about whether RAND_poll is considered part of the public API. The &amp;quot;rand&amp;quot; module contains two header files: rand.h and rand_locl.h. The first becomes part of the deployment when you install OpenSSL, whilst the latter does not. This is a common theme throughout the library. Basically anything in the *_locl.h header files should be considered private to the library, whilst anything that gets deployed should be considered part of the public API. Since RAND_poll is in rand.h (which gets deployed during installation) it should be considered part of the public API.&lt;br /&gt;
&lt;br /&gt;
--[[User:Matt|Matt]] 12:26, 9 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
: I think it would be good to get a clear statement of what constitutes the public API, because I'm getting conflicting messages.  You state that anything in an installed header file is part of the public API.  However, [[Contributions#Code_Maturity]] implies that functions are not part of the API until they are documented.  Since RAND_poll is not documented, that interpretation would suggested that RAND_poll is not yet &amp;quot;cast in stone&amp;quot; and is subject to change.&lt;br /&gt;
&lt;br /&gt;
: --[[User:Ppelleti|Ppelleti]] 00:03, 19 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
:: I don't think there is a conflict between what I said above, and what it says on [[Contributions#Code_Maturity]]. That page merely says that the API might not have completely settled down which might be the reason why there isn't any documentation. It doesn't say that the API is not &amp;quot;public&amp;quot; until its been documented.&lt;br /&gt;
&lt;br /&gt;
:: --[[User:Matt|Matt]] 21:05, 19 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
::: Sidestepping the semantics of what it means to be &amp;quot;public&amp;quot;, the real question I'm getting at is whether we should be encouraging people to use RAND_poll?  Or did the OpenSSL developers leave RAND_poll undocumented on purpose?&lt;br /&gt;
&lt;br /&gt;
::: --[[User:Ppelleti|Ppelleti]] 20:33, 20 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
:::: Well in my personal opinion, we should not avoid undocumented functions merely because they are undocumented. If you're going to do that you might as well forget anything that involves elliptic curve keys! :-)&lt;br /&gt;
&lt;br /&gt;
:::: --[[User:Matt|Matt]] 20:41, 20 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
::::: Matt, Ppelleti - I *thought* the indicator was capital versus lowercase. &amp;lt;tt&amp;gt;RAND_poll&amp;lt;/tt&amp;gt; is public, &amp;lt;tt&amp;gt;rand_poll&amp;lt;/tt&amp;gt; is private and should not be used. I believe Viktor said the same some time ago on the OpenSSL Users mailing list. I can't find the reference at the moment.&lt;br /&gt;
&lt;br /&gt;
::::: I also think presence/lack of documentation is a poor indicator. There's lots of stuff that's public that does not really have a man page.&lt;br /&gt;
&lt;br /&gt;
::::: [[User:Jwalton|Jwalton]] ([[User talk:Jwalton|talk]]) 18:52, 4 June 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
==Should we be promoting a commercial company?==&lt;br /&gt;
&lt;br /&gt;
I am a little concerned about the link to entropykey. Should we be promoting a commercial company? Whilst the text reads fine at the moment it could be the &amp;quot;thin end of the wedge&amp;quot;. This is a wiki after all. What's to stop other companies coming along and adding links to their products? How will we then decide which edits are ok, and which not? We don't want the page degenerating into a long list of products. Should we not have a policy of &amp;quot;no commerical endorsements&amp;quot;?&lt;br /&gt;
&lt;br /&gt;
--[[User:Matt|Matt]] 12:33, 9 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
: The intent was to provide a link to an inexpensive, high quality random source. Do you want to start a table *with* prices at the bottom of the page? Prices are important because some of this gear is expensive. $40 UK is dirt cheap for a FIPS approved generator. [[User:Jwalton|Jwalton]] 18:33, 30 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
: No, I think a table would be worse. Leave it for now, we can review if it turns into a problem --[[User:Matt|Matt]] 08:28, 31 March 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==No RAND_save_file function In Library==&lt;br /&gt;
This page contains reference to ''RAND_save_file'' and is not consistent with the Manual:RAND load file(3) page (and there is no prototype found with `grep -d skip RAND_save_file /usr/include/openssl/*`)&lt;br /&gt;
&lt;br /&gt;
[[User:Drankinatty|Drankinatty]] ([[User talk:Drankinatty|talk]]) 21:57, 11 July 2016 (UTC)&lt;/div&gt;</summary>
		<author><name>Drankinatty</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=Talk:EVP_Symmetric_Encryption_and_Decryption&amp;diff=2230</id>
		<title>Talk:EVP Symmetric Encryption and Decryption</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=Talk:EVP_Symmetric_Encryption_and_Decryption&amp;diff=2230"/>
		<updated>2015-06-05T04:11:00Z</updated>

		<summary type="html">&lt;p&gt;Drankinatty: Created page with &amp;quot;-- updated example to build without warnings ~~~~&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;-- updated example to build without warnings [[User:Drankinatty|Drankinatty]] ([[User talk:Drankinatty|talk]]) 04:11, 5 June 2015 (UTC)&lt;/div&gt;</summary>
		<author><name>Drankinatty</name></author>
	</entry>
	<entry>
		<id>https://wiki.openssl.org/index.php?title=EVP_Symmetric_Encryption_and_Decryption&amp;diff=2229</id>
		<title>EVP Symmetric Encryption and Decryption</title>
		<link rel="alternate" type="text/html" href="https://wiki.openssl.org/index.php?title=EVP_Symmetric_Encryption_and_Decryption&amp;diff=2229"/>
		<updated>2015-06-05T04:10:17Z</updated>

		<summary type="html">&lt;p&gt;Drankinatty: /* Setting it up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The [[Libcrypto API|libcrypto]] library within OpenSSL provides functions for performing symmetric encryption and decryption operations across a wide range of algorithms and modes. This page walks you through the basics of performing a simple encryption and corresponding decryption operation.&lt;br /&gt;
&lt;br /&gt;
In order to perform encryption/decryption you need to know:&lt;br /&gt;
* Your algorithm&lt;br /&gt;
* Your mode&lt;br /&gt;
* Your key&lt;br /&gt;
* Your Initialisation Vector (IV)&lt;br /&gt;
&lt;br /&gt;
This page assumes that you know what all of these things mean. If you don't then please refer to [[Basics of Encryption]].&lt;br /&gt;
&lt;br /&gt;
==Setting it up==&lt;br /&gt;
&lt;br /&gt;
The code below sets up the program. In this example we are going to take a simple message (&amp;quot;The quick brown fox jumps over the lazy dog&amp;quot;), and then encrypt it using a predefined key and IV. In this example the key and IV have been hard coded in - in a real situation you would never do this! Following encryption we will then decrypt the resulting ciphertext, and (hopefully!) end up with the message we first started with. This program expects two functions to be defined: &amp;quot;encrypt&amp;quot; and &amp;quot;decrypt&amp;quot;. We will define those further down the page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;openssl/conf.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;openssl/evp.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;openssl/err.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;string.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 int main (void)&lt;br /&gt;
 {&lt;br /&gt;
   /* Set up the key and iv. Do I need to say to not hard code these in a&lt;br /&gt;
    * real application? :-)&lt;br /&gt;
    */&lt;br /&gt;
 &lt;br /&gt;
   /* A 256 bit key */&lt;br /&gt;
   unsigned char *key = (unsigned char *)&amp;quot;01234567890123456789012345678901&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
   /* A 128 bit IV */&lt;br /&gt;
   unsigned char *iv = (unsigned char *)&amp;quot;01234567890123456&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
   /* Message to be encrypted */&lt;br /&gt;
   unsigned char *plaintext =&lt;br /&gt;
                 (unsigned char *)&amp;quot;The quick brown fox jumps over the lazy dog&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
   /* Buffer for ciphertext. Ensure the buffer is long enough for the&lt;br /&gt;
    * ciphertext which may be longer than the plaintext, dependant on the&lt;br /&gt;
    * algorithm and mode&lt;br /&gt;
    */&lt;br /&gt;
   unsigned char ciphertext[128];&lt;br /&gt;
 &lt;br /&gt;
   /* Buffer for the decrypted text */&lt;br /&gt;
   unsigned char decryptedtext[128];&lt;br /&gt;
 &lt;br /&gt;
   int decryptedtext_len, ciphertext_len;&lt;br /&gt;
 &lt;br /&gt;
   /* Initialise the library */&lt;br /&gt;
   ERR_load_crypto_strings();&lt;br /&gt;
   OpenSSL_add_all_algorithms();&lt;br /&gt;
   OPENSSL_config(NULL);&lt;br /&gt;
 &lt;br /&gt;
   /* Encrypt the plaintext */&lt;br /&gt;
   ciphertext_len = encrypt (plaintext, strlen ((char *)plaintext), key, iv,&lt;br /&gt;
                             ciphertext);&lt;br /&gt;
 &lt;br /&gt;
   /* Do something useful with the ciphertext here */&lt;br /&gt;
   printf(&amp;quot;Ciphertext is:\n&amp;quot;);&lt;br /&gt;
   BIO_dump_fp (stdout, (const char *)ciphertext, ciphertext_len);&lt;br /&gt;
 &lt;br /&gt;
   /* Decrypt the ciphertext */&lt;br /&gt;
   decryptedtext_len = decrypt(ciphertext, ciphertext_len, key, iv,&lt;br /&gt;
     decryptedtext);&lt;br /&gt;
 &lt;br /&gt;
   /* Add a NULL terminator. We are expecting printable text */&lt;br /&gt;
   decryptedtext[decryptedtext_len] = '\0';&lt;br /&gt;
 &lt;br /&gt;
   /* Show the decrypted text */&lt;br /&gt;
   printf(&amp;quot;Decrypted text is:\n&amp;quot;);&lt;br /&gt;
   printf(&amp;quot;%s\n&amp;quot;, decryptedtext);&lt;br /&gt;
 &lt;br /&gt;
   /* Clean up */&lt;br /&gt;
   EVP_cleanup();&lt;br /&gt;
   ERR_free_strings();&lt;br /&gt;
 &lt;br /&gt;
   return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The program sets up a 256 bit key and a 128 bit IV. This is appropriate for the 256-bit AES encryption that we going to be doing in CBC mode. Make sure you use the right key and IV length for the cipher you have selected, or it will go horribly wrong!!&lt;br /&gt;
&lt;br /&gt;
We've also set up a buffer for the ciphertext to be placed in. It is important to ensure that this buffer is sufficiently large for the expected ciphertext or you may see a program crash (or potentially introduce a security vulnerability into your code). Note: The ciphertext may be longer than the plaintext (e.g. if padding is being used).&lt;br /&gt;
&lt;br /&gt;
We're also going to need a helper function to handle any errors. This will simply dump any error messages from the OpenSSL error stack to the screen, and then abort the program.&lt;br /&gt;
&lt;br /&gt;
 void handleErrors(void)&lt;br /&gt;
 {&lt;br /&gt;
   ERR_print_errors_fp(stderr);&lt;br /&gt;
   abort();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Encrypting the message==&lt;br /&gt;
&lt;br /&gt;
So now that we have set up the program we need to define the &amp;quot;encrypt&amp;quot; function. This will take as parameters the plaintext, the length of the plaintext, the key to be used, and the IV. We'll also take in a buffer to put the ciphertext in (which we assume to be long enough), and will return the length of the ciphertext that we have written.&lt;br /&gt;
&lt;br /&gt;
Encrypting consists of the following stages:&lt;br /&gt;
* Setting up a context&lt;br /&gt;
* Initialising the encryption operation&lt;br /&gt;
* Providing plaintext bytes to be encrypted&lt;br /&gt;
* Finalising the encryption operation&lt;br /&gt;
&lt;br /&gt;
During initialisation we will provide an EVP_CIPHER object. In this case we are using EVP_aes_256_cbc(), which uses the AES algorithm with a 256-bit key in [[CBC]] mode. Refer to [[EVP#Working with Algorithms and Modes]] for further details.&lt;br /&gt;
&lt;br /&gt;
 int encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *key,&lt;br /&gt;
   unsigned char *iv, unsigned char *ciphertext)&lt;br /&gt;
 {&lt;br /&gt;
   EVP_CIPHER_CTX *ctx;&lt;br /&gt;
 &lt;br /&gt;
   int len;&lt;br /&gt;
 &lt;br /&gt;
   int ciphertext_len;&lt;br /&gt;
 &lt;br /&gt;
   /* Create and initialise the context */&lt;br /&gt;
   if(!(ctx = EVP_CIPHER_CTX_new())) handleErrors();&lt;br /&gt;
 &lt;br /&gt;
   /* Initialise the encryption operation. IMPORTANT - ensure you use a key&lt;br /&gt;
    * and IV size appropriate for your cipher&lt;br /&gt;
    * In this example we are using 256 bit AES (i.e. a 256 bit key). The&lt;br /&gt;
    * IV size for *most* modes is the same as the block size. For AES this&lt;br /&gt;
    * is 128 bits */&lt;br /&gt;
   if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))&lt;br /&gt;
     handleErrors();&lt;br /&gt;
 &lt;br /&gt;
   /* Provide the message to be encrypted, and obtain the encrypted output.&lt;br /&gt;
    * EVP_EncryptUpdate can be called multiple times if necessary&lt;br /&gt;
    */&lt;br /&gt;
   if(1 != EVP_EncryptUpdate(ctx, ciphertext, &amp;amp;len, plaintext, plaintext_len))&lt;br /&gt;
     handleErrors();&lt;br /&gt;
   ciphertext_len = len;&lt;br /&gt;
 &lt;br /&gt;
   /* Finalise the encryption. Further ciphertext bytes may be written at&lt;br /&gt;
    * this stage.&lt;br /&gt;
    */&lt;br /&gt;
   if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &amp;amp;len)) handleErrors();&lt;br /&gt;
   ciphertext_len += len;&lt;br /&gt;
 &lt;br /&gt;
   /* Clean up */&lt;br /&gt;
   EVP_CIPHER_CTX_free(ctx);&lt;br /&gt;
 &lt;br /&gt;
   return ciphertext_len;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Decrypting the Message==&lt;br /&gt;
&lt;br /&gt;
Finally we need to define the &amp;quot;decrypt&amp;quot; operation. This is very similar to encryption and consists of the following stages:&lt;br /&gt;
Encrypting consists of the following stages:&lt;br /&gt;
* Setting up a context&lt;br /&gt;
* Initialising the decryption operation&lt;br /&gt;
* Providing ciphertext bytes to be decrypted&lt;br /&gt;
* Finalising the decryption operation&lt;br /&gt;
&lt;br /&gt;
Again through the parameters we will receive the ciphertext to be decrypted, the length of the ciphertext, the key and the IV. We'll also receive a buffer to place the decrypted text into, and return the length of the plaintext we have found.&lt;br /&gt;
&lt;br /&gt;
Note that we have passed the length of the ciphertext. This is required as you cannot use functions such as &amp;quot;strlen&amp;quot; on this data - its binary! Similarly, even though in this example our plaintext really is ASCII text, OpenSSL does not know that. In spite of the name plaintext could be binary data, and therefore no NULL terminator will be put on the end (unless you encrypt the NULL as well of course).&lt;br /&gt;
&lt;br /&gt;
Here is the decrypt function:&lt;br /&gt;
&lt;br /&gt;
 int decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,&lt;br /&gt;
   unsigned char *iv, unsigned char *plaintext)&lt;br /&gt;
 {&lt;br /&gt;
   EVP_CIPHER_CTX *ctx;&lt;br /&gt;
 &lt;br /&gt;
   int len;&lt;br /&gt;
 &lt;br /&gt;
   int plaintext_len;&lt;br /&gt;
 &lt;br /&gt;
   /* Create and initialise the context */&lt;br /&gt;
   if(!(ctx = EVP_CIPHER_CTX_new())) handleErrors();&lt;br /&gt;
 &lt;br /&gt;
   /* Initialise the decryption operation. IMPORTANT - ensure you use a key&lt;br /&gt;
    * and IV size appropriate for your cipher&lt;br /&gt;
    * In this example we are using 256 bit AES (i.e. a 256 bit key). The&lt;br /&gt;
    * IV size for *most* modes is the same as the block size. For AES this&lt;br /&gt;
    * is 128 bits */&lt;br /&gt;
   if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv))&lt;br /&gt;
     handleErrors();&lt;br /&gt;
 &lt;br /&gt;
   /* Provide the message to be decrypted, and obtain the plaintext output.&lt;br /&gt;
    * EVP_DecryptUpdate can be called multiple times if necessary&lt;br /&gt;
    */&lt;br /&gt;
   if(1 != EVP_DecryptUpdate(ctx, plaintext, &amp;amp;len, ciphertext, ciphertext_len))&lt;br /&gt;
     handleErrors();&lt;br /&gt;
   plaintext_len = len;&lt;br /&gt;
 &lt;br /&gt;
   /* Finalise the decryption. Further plaintext bytes may be written at&lt;br /&gt;
    * this stage.&lt;br /&gt;
    */&lt;br /&gt;
   if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &amp;amp;len)) handleErrors();&lt;br /&gt;
   plaintext_len += len;&lt;br /&gt;
 &lt;br /&gt;
   /* Clean up */&lt;br /&gt;
   EVP_CIPHER_CTX_free(ctx);&lt;br /&gt;
 &lt;br /&gt;
   return plaintext_len;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Output==&lt;br /&gt;
&lt;br /&gt;
If all goes well you should end up with output that looks like the following:&lt;br /&gt;
 Ciphertext is:&lt;br /&gt;
 0000 - e0 6f 63 a7 11 e8 b7 aa-9f 94 40 10 7d 46 80 a1   .oc.......@.}F..&lt;br /&gt;
 0010 - 17 99 43 80 ea 31 d2 a2-99 b9 53 02 d4 39 b9 70   ..C..1....S..9.p&lt;br /&gt;
 0020 - 2c 8e 65 a9 92 36 ec 92-07 04 91 5c f1 a9 8a 44   ,.e..6.....\...D&lt;br /&gt;
 Decrypted text is:&lt;br /&gt;
 The quick brown fox jumps over the lazy dog&lt;br /&gt;
&lt;br /&gt;
For further details about symmetric encryption and decryption operations refer to the OpenSSL documentation [[Manual:EVP_EncryptInit(3)]].&lt;br /&gt;
&lt;br /&gt;
==Notes on some unusual modes==&lt;br /&gt;
&lt;br /&gt;
Worthy of mention here is the [[XTS]] mode (e.g. EVP_aes_256_xts()). This works in exactly the same way as shown above, except that the &amp;quot;tweak&amp;quot; is provided in the IV parameter. A further &amp;quot;gotcha&amp;quot; is that XTS mode expects a key which is twice as long as normal. Therefore EVP_aes_256_xts() expects a key which is 512-bits long.&lt;br /&gt;
&lt;br /&gt;
Authenticated encryption modes ([[GCM]] or [[CCM]]) work in essentially the same way as shown above but require some special handling. See [[EVP Authenticated Encryption and Decryption]] for further details.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[EVP]]&lt;br /&gt;
* [[Libcrypto API]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Crypto API]]&lt;br /&gt;
[[Category:C level]]&lt;br /&gt;
[[Category:Examples]]&lt;/div&gt;</summary>
		<author><name>Drankinatty</name></author>
	</entry>
</feed>