Cryptography in C and C (2nd ed.) [Welschenbach 2013].pdf

(2471 KB) Pobierz
Cryptography
in C and C++
MICHAEL WELSCHENBACH
Translated by DAVID KRAMER
A
press
TM
Cryptography in C and C++
c
Copyright
2005 by Michael Welschenbach
Translator and Compositor: David Kramer
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell,
Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Assistant Publisher: Grace Wong
Copy Manager: Nicole LeClerc
Production Manager: Kari Brooks-Copony
Proofreader: Anne Friedman
TEX Support: Fred Bartlett and Arthur Ogawa
Manufacturing Manager: Tom Debolski
Cover Designer: Kurt Krames
Library of Congress Cataloging-in-Publication Data
Welschenbach, Michael.
[Kryptographie in C und C++. English]
Cryptography in C and C++ / Michael Welschenbach ; translated by David Kramer.–
2nd American ed., rev. and enl.
p. cm.
The first American edition is a translation of the second German edition, which has
been revised and expanded from the first German edition.
Includes bibliographical references and index.
ISBN 1-59059-502-5
1. Computer security. 2. Cryptography. 3. C (Computer program
language) 4. C++ (Computer program language) I. Title.
QA76.9.A25W4313 2005
005.8–dc22
2005002553
All rights reserved. No part of this work may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 233 Spring
Street, 6th Floor, New York, NY 10013, and outside the United States by Springer-Verlag GmbH &
Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany.
In the United States: phone 1-800-SPRINGER, fax 201-348-4505, e-mail
orders@springer-ny.com,
or visit
http://www.springer-ny.com.
Outside the United States: fax +49 6221 345229, e-mail
orders@springer.de,
or visit
http://www.springer.de.
For information on translations, please
contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930,
fax 510-549-5939, e-mail
info@apress.com,
or visit
http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at
http://www.apress.com
in the Downloads
section. You will need to answer questions pertaining to this book in order to successfully
download the code.
To my family, as always
Contents
Foreword
About the Author
About the Translator
Preface to the Second American Edition
Preface to the First American Edition
Preface to the First German Edition
xiii
xv
xvi
xvii
xix
xxiii
I
Arithmetic and Number Theory in C
1
3
13
19
23
24
33
34
40
45
50
67
81
81
86
101
106
118
1 Introduction
2 Number Formats: The Representation of Large Numbers in C
3 Interface Semantics
4 The Fundamental Operations
4.1 Addition and Subtraction . . . . . . . . . . .
4.2 Multiplication . . . . . . . . . . . . . . . . .
4.2.1 The Grade School Method . . . . . .
4.2.2 Squaring Is Faster . . . . . . . . . . .
4.2.3 Do Things Go Better with Karatsuba?
4.3 Division with Remainder . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5 Modular Arithmetic: Calculating with Residue Classes
6 Where All Roads Meet: Modular Exponentiation
6.1 First Approaches . . . . . . . . . . . . . . .
6.2
M
-ary Exponentiation . . . . . . . . . . . .
6.3 Addition Chains and Windows . . . . . . . .
6.4 Montgomery Reduction and Exponentiation
6.5 Cryptographic Application of Exponentiation
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
v
Zgłoś jeśli naruszono regulamin