{"id":1443,"date":"2010-12-15T12:45:51","date_gmt":"2010-12-15T16:45:51","guid":{"rendered":"http:\/\/www.acarlstein.com\/?p=1443"},"modified":"2010-12-15T15:23:51","modified_gmt":"2010-12-15T19:23:51","slug":"introduction-to-network-security-%e2%80%93-part-10","status":"publish","type":"post","link":"http:\/\/blog.acarlstein.com\/?p=1443","title":{"rendered":"Introduction to Network Security \u2013 Part 10"},"content":{"rendered":"<p><strong>NOTIFICATION:<\/strong><strong> <\/strong>These examples are provided for educational purposes. The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is given \u2018as is\u2019. I do not take responsibilities of how they are used. You are welcome to point out any mistakes in my posting and\/or leave a comment.<\/p>\n<p><strong>RSA Algorithm<br \/>\n<\/strong><\/p>\n<p>RSA is an algorithm for public-key cryptography. The signals <span style=\"color: #ff0000;\">R.S.A.<\/span> come from the last name of Ron <span style=\"color: #ff0000;\">R<\/span>ivest, Adi <span style=\"color: #ff0000;\">S<\/span>hamir, and Leonard <span style=\"color: #ff0000;\">A<\/span>dleman who where the first to describe this algorithm. This algorithm is famous for being the first suitable algorithm for signing as well as encryption.<\/p>\n<p>RSA algorithm allow to choose which key should be use for encryption and decryption.<\/p>\n<ol>\n<li>Public key for encryption, private key for decryption or,<\/li>\n<li>Private key for encryption, public key for decryption.<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Generate the Pair Key (Public and Private Key)<br \/>\n<\/span><\/p>\n<ol>\n<li>Choose two random prime numbers <em>p<\/em> and <em>q<\/em>.<br \/>\n<span style=\"color: #0000ff;\"><em>p<\/em> = 17<br \/>\n<em>q<\/em> = 11 <\/span><br \/>\nFor better security, you can use the Primality Test to obtain to obtain these two random prime number. They should be of similar bit-length.<\/li>\n<li>Compute <em>n = p*q<\/em> in which n is the modulus used for both the private and public keys.<br \/>\n<span style=\"color: #0000ff;\"><em>n = p * q<\/em> = 17 * 11 = 187<\/span><\/li>\n<li>Compute Euler Totient Function \u00f8(n)<br \/>\n<span style=\"color: #0000ff;\"><em>\u00f8(n) = <\/em><em>\u00f8(187)<\/em><em> = (p &#8211; 1) * (q &#8211; 1)<\/em> = 16 * 10 = 160<\/span><\/li>\n<li>Select a public key exponent <em>e<\/em> number where 1 &lt; <em>e<\/em> &lt; <em>\u00f8(n)<\/em> and <em>gcd(e, \u00f8(n)<\/em>) = 1<br \/>\nIf we choose <span style=\"color: #0000ff;\"><em>e<\/em> = 7<\/span> then <span style=\"color: #0000ff;\">gcd(e, <em>\u00f8(n)<\/em>) = <em>gcd<\/em>(7, 160) = 1<\/span><\/li>\n<li>Determine the multiplicative inverse d:<br \/>\n<a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-2.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-2\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-2.png\" alt=\"\" width=\"186\" height=\"25\" \/><\/a><\/p>\n<ol>\n<li>d must be less than \u00f8(n): <em><span style=\"color: #0000ff;\">d &lt; 160<\/span><\/em><\/li>\n<li>if <em>d * e mod \u00f8(n)<\/em> =  <em>d<\/em> * 7 <em>mod \u00f8(187)<\/em> = d * 7 <em>mod<\/em> 160 = 1 then<\/li>\n<li>let <span style=\"color: #0000ff;\">d = 23<\/span> in this way <span style=\"color: #0000ff;\"><em>d * e = 23 * 7 = 161 = (160 + 1)<\/em><\/span><br \/>\n<em><span style=\"color: #0000ff;\">d * 7 mod 160 = 23 * 7 mod 160 = 1<\/span><\/em><\/li>\n<\/ol>\n<\/li>\n<li>The public key will be:<br \/>\n<em><span style=\"color: #0000ff;\">PU = {e, n} = {7, 187}<\/span><\/em><\/li>\n<li>The private key will be:<br \/>\n<em><span style=\"color: #0000ff;\">PR = {d, n} = {23, 187}<\/span><\/em><\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Encryption<\/span><\/p>\n<ol>\n<li>Sender must obtain the public key <em>PU = {e, n} <\/em>to the recipient, where <em>PU<\/em> is the public key, <em>n<\/em> for modulus, and <em>e<\/em> for public exponent (also known as public encryption).<br \/>\n<span style=\"color: #0000ff;\"><em>PU = {e, n} = {7, 187}<\/em><\/span><\/li>\n<li>The message <em>M<\/em> (also known as the plaintext) must be turn into an integer <em>m<\/em> by using a padding scheme (an reversible protocol) in which <em>0 &lt; m &lt; n.<br \/>\n<\/em>Lets assume the message is <em><span style=\"color: #0000ff;\">m = 88<\/span> where 0 &lt; m &lt; n so <\/em><em><span style=\"color: #0000ff;\">0 &lt; 88 &lt; 187<\/span>.<\/em><em><br \/>\n<\/em><\/li>\n<li>Then the sender must compute the ciphertext.<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1446\" title=\"Screenshot\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot1.png\" alt=\"\" width=\"120\" height=\"23\" \/><\/a><br \/>\nWhere <em>c<\/em> is the ciphertext, <em>m<\/em> is the integer message , <em>e<\/em> is the public exponent, and <em>n<\/em> i for modulus.<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-31.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1451\" title=\"Screenshot-3\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-31.png\" alt=\"\" width=\"139\" height=\"16\" \/><\/a><\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Decryption<\/span><\/p>\n<ol>\n<li>The recipient must use the private key to decrypt the ciphertext <span style=\"color: #000000;\"><em>PR = {d, n} <\/em><\/span>where <em>PR<\/em> is the private key, <em>d<\/em> is the private key exponent, <em>n<\/em> for modulus.<br \/>\n<span style=\"color: #0000ff;\"><em>PR = {d, n} = {23, 187}<\/em><\/span><\/li>\n<li>Compute the message.<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1448\" title=\"Screenshot-1\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-11.png\" alt=\"\" width=\"125\" height=\"22\" \/><\/a><br \/>\nWhere <em>m<\/em> is the integer message, <em>c<\/em> is the ciphertext, <em>n<\/em> for modulus.<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-41.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1452\" title=\"Screenshot-4\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-41.png\" alt=\"\" width=\"149\" height=\"16\" \/><\/a><\/li>\n<li>Then turn back the original message M by using\u00a0 integer message <em>m<\/em> with the reverse padding scheme.<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Encryption \/ Decryption Example<\/span><\/p>\n<p><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-51.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1453\" title=\"Screenshot-5\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-51.png\" alt=\"\" width=\"397\" height=\"125\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-51.png 397w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-51-300x94.png 300w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\">Algorithm Requirements<\/span><\/p>\n<ol>\n<li> <a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1454\" title=\"Screenshot-6\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-6.png\" alt=\"\" width=\"175\" height=\"40\" \/><\/a><\/li>\n<li>There should be able to find values for e, d, and n so for all values of m where 0 &lt; M &lt; n<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-6b.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1455\" title=\"Screenshot-6b\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-6b.png\" alt=\"\" width=\"100\" height=\"20\" \/><\/a><\/li>\n<li><a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot1.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot1.png\" alt=\"\" width=\"120\" height=\"23\" \/><\/a> and <a href=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-11.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Screenshot-1\" src=\"..\/wp-content\/uploads\/2010\/12\/Screenshot-11.png\" alt=\"\" width=\"125\" height=\"22\" \/><\/a> should be easy to calculate for all valus of m where 0 &lt; m &lt; n.<\/li>\n<li>It should be very hard for an attacker to determine <em>d<\/em> given <em>e<\/em> and <em>n<\/em><\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Possible Attacks to RSA<\/span><\/p>\n<ol>\n<li>Brute Attack<\/li>\n<li>Mathematical attacks\n<ol>\n<li>Determine <em>d<\/em> directly<\/li>\n<li>Determine the Euler Totient Function <em>\u00f8(n)<\/em> without using the prime numbers <em>p<\/em> and <em>q<\/em><\/li>\n<li>Factorising <em>n<\/em> into the correct prime factors <em>p<\/em> and <em>q<\/em><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>Key Distribution<\/strong><\/p>\n<p>One of the important aspects is how to distribute the keys between the sender and the receiver. For example, one way is to use the public-key encryption to distribute the keys.<\/p>\n<p>For doing that there are three different methods of distributions that can be used:<\/p>\n<ol>\n<li>Public announcement,<\/li>\n<li>Public-key authority, and<\/li>\n<li>Public-key certificates<\/li>\n<\/ol>\n<p><strong>Public Annoucement<\/strong><\/p>\n<p>One way to distribute the public keys is having the sender to distribute the public key to the recipient; however, this have the disadvantage that an attacker could create a key claiming to be the sender. This disadvantage is known as forgery.<\/p>\n<p>A solution is to create a public-key autority.<\/p>\n<p><span style=\"text-decoration: underline;\">Public Key Authority<\/span><\/p>\n<p>A public key authority is a central authority that maintain a dynamic directory of public keys for all the users. Example: {name, public-key}<\/p>\n<ol>\n<li>In a secure way (in person), each user register a public key in this directory authority.<\/li>\n<li>It is required that the user known the public key for the directory.<\/li>\n<li>Only the authority known the corresponding private key<\/li>\n<li>Users interact with the directory in order to obtain the public key securely<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Steps:<\/span><\/p>\n<ol>\n<li>User A send\u00a0 a timestamped message to the public key authority.<br \/>\nThis message contain a request for the public key of user B.<\/li>\n<li>The public-key authority responds to user A returning an encrypted message using it&#8217;s private key. This message contains:\n<ol>\n<li>The original request so it can be use to match with the request<\/li>\n<li>The original timestamp so it can be determined if the message is not from the public-key authority.<\/li>\n<li>The public key of user B.<\/li>\n<\/ol>\n<\/li>\n<li>User A store the public-key of user B and use this public-key to encrypt a message that will contain the identity of user A plus a &#8220;nonce N1&#8221;. This message will be deliver to user B.<\/li>\n<li>User B send\u00a0 a timestamped message to the public key authority.<br \/>\nThis message contain a request for the public key of user A.<\/li>\n<li>The public-key authority responds to user B returning an encrypted message using it&#8217;s private key. This message contains:\n<ol>\n<li>The original request so it can be use to match with the request<\/li>\n<li>The original timestamp so it can be determined if the message is not from the public-key authority.<\/li>\n<li>The public key of user A.<\/li>\n<\/ol>\n<\/li>\n<li>User B encrypt a message using the public-key of user A and send this encrypted message to user A.<br \/>\nThis encrypted message have:<\/p>\n<ol>\n<li>User A&#8217;s nonce<\/li>\n<li>A nonce genereated by User B<\/li>\n<\/ol>\n<\/li>\n<li>User A encrypt a message using the public-key of User B and send this encrypted message to user B.<br \/>\nThis encrypted message holds:<\/p>\n<ol>\n<li>the\u00a0 nonce N2 of user A<\/li>\n<\/ol>\n<p>(This will ensure user B that the encrypted message is coming from user A).<\/li>\n<\/ol>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1458 aligncenter\" title=\"Screenshot-9\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-9.png\" alt=\"\" width=\"617\" height=\"346\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-9.png 815w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-9-300x168.png 300w\" sizes=\"auto, (max-width: 617px) 100vw, 617px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\">Disavantages:<\/span><\/p>\n<p>Since the users must appeal to the public-key authority in order to obtain the other users&#8217; public key it can produce a bottleneck.<\/p>\n<p><strong>Public Key Certificates<\/strong><\/p>\n<p>Another way to exchange keys without the need of a public-key authority is the public-key certificates. The general idea would be:<\/p>\n<ol>\n<li>A certificate is a data block that contains a public key plus an identifier of the key&#8217;s owner. This data block would be signed by a trusted third party which would be the certificate authority.<\/li>\n<li>A user would generate a pair key and send the public key to this certify authority in a secure way and obtain a certificate issued by the certify authority (the trusted third party).<\/li>\n<li>This user then would publish this certificate so another user can verify that the certificate was created by the trusted third party.<\/li>\n<\/ol>\n<p>Please notice that the certificate authority (the trusted third party) is the only one that can create and update certificates.<\/p>\n<p><span style=\"text-decoration: underline;\">Steps:<\/span><\/p>\n<ol>\n<li>User A supply a public key <span style=\"color: #ff0000;\"><em>PUa<\/em><\/span> with a request for a certificate to the certificate authority. This request must be done in a secure ways such as in person for example.<\/li>\n<li>The certificate authority would provide user A with this from:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1463\" title=\"Screenshot-10\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-10.png\" alt=\"\" width=\"223\" height=\"18\" \/><\/a> where <span style=\"color: #ff0000;\"><em>E<\/em><\/span> is the encryption algorithm,<span style=\"color: #ff0000;\"><em> PRauth<\/em><\/span> is the authority&#8217;s private key and <em><span style=\"color: #ff0000;\">Time1<\/span><\/em> is a timestamp, and <em><span style=\"color: #ff0000;\">IDa<\/span><\/em> is the user A identification.<\/li>\n<li>User A then can pass the certificate CA any user (in this case user B).<\/li>\n<li>User B get the certificate from user A and verify if the certificate correspond to the certify authority by decrypting the message using the authority&#8217;s public key:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-111.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1464\" title=\"Screenshot-11\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-111.png\" alt=\"\" width=\"404\" height=\"16\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-111.png 375w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-111-300x12.png 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/a><br \/>\nIn this way it can verify that the certificate is not counterfeit.<\/li>\n<\/ol>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1466 aligncenter\" title=\"Screenshot-12\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/12\/Screenshot-12.png\" alt=\"\" width=\"698\" height=\"363\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-12.png 865w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/12\/Screenshot-12-300x156.png 300w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/a><\/p>\n\n<script>\nvar zbPregResult = '0';\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>NOTIFICATION: These examples are provided for educational purposes. The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is given \u2018as is\u2019. I do not take responsibilities of how they are used. You are welcome to point out any mistakes in my posting and\/or leave a comment. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,264],"tags":[452,42,456,316,321,323,453,338,460,454,431,423,324,88,313,455,457,458,459,450,449,451],"class_list":["post-1443","post","type-post","status-publish","format-standard","hentry","category-programming","category-network-security","tag-adleman","tag-algorithm","tag-authority","tag-ciphertext","tag-decryption","tag-encryption","tag-exponent","tag-key","tag-key-distribution","tag-message","tag-modulus","tag-number","tag-plaintext","tag-prime","tag-private","tag-public","tag-public-announcement","tag-public-key-authority","tag-public-key-certificates","tag-rivest","tag-rsa","tag-shamir"],"_links":{"self":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1443"}],"version-history":[{"count":13,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1443\/revisions"}],"predecessor-version":[{"id":1457,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1443\/revisions\/1457"}],"wp:attachment":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1443"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}