applied cryptography - protocols, algorithms, and source code in c

To access the contents click the chapter and section

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the individual modular multiplications. Because the operations are distributive, it is faster to do the exponentiation as a stream of successive multiplications, taking the modulus every time. It doesn’t make much difference now, but it will when you’re working with 200-bit numbers. For example, if you want to calculate a8 mod n, don’t use the naïve approach and perform seven multiplications and one huge modular reduction: (a*a*a*a*a*a*a*a) mod n Instead, perform three smaller multiplications and three smaller modular reductions: ((a2 mod n)2 mod n)2 mod n By the same token, a16 mod n = (((a2 mod n)2 mod n)2 mod n)2 mod n Previous Table of Contents Next Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. To access the contents, click the chapter and section titles. Applied Cryptography, Second Edition: Protocols, Algorthms, and Source Code in C (cloth) Go! Keyword Brief Full Advanced Search Search Tips (Publisher: John Wiley & Sons, Inc.) Author(s): Bruce Schneier ISBN: 0471128457 Publication Date: 01/01/96 Search this book: Go! Previous Table of Contents Next ----------- Computing ax mod n, where x is not a power of 2, is only slightly harder. Binary notation expresses x as a sum of powers of 2: 25 is 11001 in binary, so 25 = 24 + 23 + 20. So a25 mod n = (a*a24) mod n = (a*a8*a16) mod n = (a*((a2)2)2*(((a2)2)2)2) mod n = ((((a2*a)2)2)2*a) mod n With judicious storing of intermediate results, you only need six multiplications: (((((((a2 mod n)*a) mod n)2 mod n)2 mod n)2 mod n)*a) mod n This is called addition chaining [863], or the binary square and multiply method. It uses a simple and obvious addition chain based on the binary representation. In C, it looks like: unsigned long qe2(unsigned long x, unsigned l...
View Full Document

This note was uploaded on 10/18/2010 for the course MATH CS 301 taught by Professor Aliulger during the Fall '10 term at Koç University.

Ask a homework question - tutors are online