~ubuntu-branches/ubuntu/raring/libgcrypt11/raring

« back to all changes in this revision

Viewing changes to doc/HACKING

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2008-07-02 18:32:45 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080702183245-b1p9zumbhmq9wk4g
Tags: 1.4.1-1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Add libgcrypt11-udeb package.
  - Add clean-la.mk, and add a symlink for the .la
* Ubuntu changes dropped:
  - Build-Depends changes.
  - Drop patch 20_socket_nsl_linkage.diff, basically applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
                        Various hacking notes                  -*- text -*-
 
2
                       =======================
 
3
 
 
4
 
 
5
Taking optimized MPI code out of GMP:
 
6
-------------------------------------
 
7
 
 
8
  I generated the pentium4/* files by glueing the existing assembler
 
9
  prologues to the GMP 4.2.1 assembler files generated with the m4
 
10
  tool in GMP's build process, for example:
 
11
 
 
12
    $ m4 -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_rshift -DPIC \
 
13
      rshift.asm >tmp-rshift.s
 
14
 
 
15
  Then tmp-rshift will contain the assembler instructions for the
 
16
  configured platform.  Unfortunately, this way the comments are lost.
 
17
  For most files I re-inserted some of the comments, but this is
 
18
  tedious work.
 
19
 
 
20
 
 
21
Debugging math stuff:
 
22
---------------------
 
23
 
 
24
  While debugging the ECC code in libgcrypt, I was in need for some
 
25
  computer algebra system which would allow me to verify the numbers
 
26
  in the debugging easily.  I found that PARI (pari-gp package in
 
27
  Debian) has support for elliptic curves.  The below commands shows
 
28
  how they are set up and used with an example.
 
29
 
 
30
  ===8<========
 
31
  hextodec(s)=local(v=Vec(s),a=10,b=11,c=12,d=13,e=14,f=15,A=10,B=11,C=12,D=13,E=14,F=15,h);if(#setunion(Set(v),Vec("0123456789ABCDEFabcdef"))>22,error);for(i=1,#v,h=shift(h,4)+eval(v[i]));h
 
32
  
 
33
  p = hextodec("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
 
34
  a = hextodec("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC")
 
35
  b = hextodec("51953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00")
 
36
  
 
37
  /* Set up y^2 = x^3 + ax + b mod (p).  */
 
38
  e = ellinit(Mod(1,p)*[0,0,0,a,b]);
 
39
  
 
40
  gx = hextodec ("00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66")
 
41
  gy = hextodec ("011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650")
 
42
  g = Mod(1,p)*[gx,gy]
 
43
  
 
44
  n = hextodec ("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409")
 
45
  
 
46
  /* Verify that G is on the curve, and that n is the order.  */
 
47
  ellisoncurve (e,g)
 
48
  isprime (n)
 
49
  ellpow (e,g,n)
 
50
  
 
51
  d = hextodec ("018F9573F25059571BDF614529953DE2540497CEDABD04F3AF78813BED7BB163A2FD919EECF822848FCA39EF55E500F8CE861C7D53D371857F7774B79428E887F81B")
 
52
  
 
53
  qx = hextodec ("00316AAAD3E905875938F588BD9E8A4785EF9BDB76D62A83A5340F82CB8E800B25619F5C3EA02B7A4FA43D7497C7702F7DFBEAC8E8F92C3CAABD9F84182FDA391B3B")
 
54
  /* Note: WRONG! (It is apparent that this is the same as X shifted by
 
55
     8 bit).  */
 
56
  qy = hextodec ("0000316AAAD3E905875938F588BD9E8A4785EF9BDB76D62A83A5340F82CB8E800B25619F5C3EA02B7A4FA43D7497C7702F7DFBEAC8E8F92C3CAABD9F84182FDA391B")
 
57
  q = Mod(1,p)*[qx,qy]
 
58
  
 
59
  /* Calculate what Q should be given d.  */
 
60
  ellpow (e,g,d)
 
61
  
 
62
  /* This is not 0 and thus shows that libgcrypt gave Q and d that do
 
63
  not match.  */
 
64
  ellpow (e,g,d) - q
 
65
  ====8<=====================
 
66