<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -32,35 +32,24 @@ extern void randombytes(uint8_t*buffer,unsigned long long length);
 #line 81 &quot;rwb0fuz1024.w&quot;
 
 /*5:*/
-#line 101 &quot;rwb0fuz1024.w&quot;
+#line 102 &quot;rwb0fuz1024.w&quot;
 
 static void
 init_random_prime(mpz_t n,unsigned size,unsigned mod8){
 uint8_t buffer[256];
 const unsigned bytes= size&gt;&gt;3;
 
-if(bytes&gt; sizeof(buffer))
+if(bytes==0||bytes&gt; sizeof(buffer))
 abort();
 
-mpz_init2(n,bytes);
+mpz_init2(n,size);
 
 for(;;){
 randombytes(buffer,bytes);
 
+buffer[bytes-1]&amp;= ~7;
+buffer[bytes-1]|= mod8;
 mpz_import(n,bytes,1,1,0,0,buffer);
-mpz_setbit(n,0);
-
-if(mod8&amp;2){
-mpz_setbit(n,1);
-}else{
-mpz_clrbit(n,1);
-}
-
-if(mod8&amp;4){
-mpz_setbit(n,2);
-}else{
-mpz_clrbit(n,2);
-}
 
 if(mpz_probab_prime_p(n,32))
 break;
@@ -71,7 +60,7 @@ break;
 #line 82 &quot;rwb0fuz1024.w&quot;
 
 /*16:*/
-#line 363 &quot;rwb0fuz1024.w&quot;
+#line 353 &quot;rwb0fuz1024.w&quot;
 
 static void
 hash(mpz_t e,const uint8_t*m,unsigned mlen){
@@ -100,30 +89,33 @@ mpz_import(e,128,1,1,1,0,element);
 #line 83 &quot;rwb0fuz1024.w&quot;
 
 /*27:*/
-#line 600 &quot;rwb0fuz1024.w&quot;
+#line 590 &quot;rwb0fuz1024.w&quot;
 
 static uint8_t
 HMAC_SHA512(const uint8_t*key,
 const uint8_t*value,unsigned valuelen){
 unsigned i;
-uint8_t keycopy[8];
+uint8_t keycopy[128];
+
+for(i= 0;i&lt;128;++i)
+keycopy[i]= 0x5c;
 
 for(i= 0;i&lt;8;++i)
-keycopy[i]= key[i]^0x5c;
+keycopy[i]^= key[i];
 
 SHA512_CTX shactx;
 SHA512_Init(&amp;shactx);
-SHA512_Update(&amp;shactx,keycopy,8);
+SHA512_Update(&amp;shactx,keycopy,128);
 SHA512_Update(&amp;shactx,value,valuelen);
 
 uint8_t t[64];
 SHA512_Final(t,&amp;shactx);
 
-for(i= 0;i&lt;8;++i)
-keycopy[i]^= 0x6a;
+for(i= 0;i&lt;128;++i)
+keycopy[i]^= (0x5c^0x36);
 
 SHA512_Init(&amp;shactx);
-SHA512_Update(&amp;shactx,keycopy,8);
+SHA512_Update(&amp;shactx,keycopy,128);
 SHA512_Update(&amp;shactx,t,sizeof(t));
 SHA512_Final(t,&amp;shactx);
 
@@ -134,7 +126,7 @@ return t[0];
 #line 84 &quot;rwb0fuz1024.w&quot;
 
 /*12:*/
-#line 233 &quot;rwb0fuz1024.w&quot;
+#line 223 &quot;rwb0fuz1024.w&quot;
 
 static void
 xgcd(mpz_t u,mpz_t v,mpz_t ip,mpz_t iq){
@@ -181,14 +173,14 @@ mpz_clear(t);
 #line 85 &quot;rwb0fuz1024.w&quot;
 
 /*6:*/
-#line 142 &quot;rwb0fuz1024.w&quot;
+#line 132 &quot;rwb0fuz1024.w&quot;
 
 int
 crypto_sign_rwb0fuz1024_gmp_keypair(uint8_t*pk,uint8_t*sk){
 mpz_t p,q,n;
 
 /*7:*/
-#line 162 &quot;rwb0fuz1024.w&quot;
+#line 152 &quot;rwb0fuz1024.w&quot;
 
 for(;;){
 init_random_prime(p,512,3);
@@ -196,39 +188,39 @@ init_random_prime(q,512,7);
 mpz_init(n);
 mpz_mul(n,p,q);
 
-if(mpz_scan1(n,1024-8)==ULONG_MAX){
+if(mpz_scan1(n,1024-8)!=ULONG_MAX){
+break;
+}
+
 mpz_clear(n);
 mpz_clear(p);
 mpz_clear(q);
-}else{
-break;
-}
 }
 
 /*:7*/
-#line 147 &quot;rwb0fuz1024.w&quot;
+#line 137 &quot;rwb0fuz1024.w&quot;
 
 /*8:*/
-#line 183 &quot;rwb0fuz1024.w&quot;
+#line 173 &quot;rwb0fuz1024.w&quot;
 
 mpz_t u,v;
 xgcd(u,v,p,q);
 mpz_mul(u,u,p);
 
 /*:8*/
-#line 148 &quot;rwb0fuz1024.w&quot;
+#line 138 &quot;rwb0fuz1024.w&quot;
 
 /*9:*/
-#line 193 &quot;rwb0fuz1024.w&quot;
+#line 183 &quot;rwb0fuz1024.w&quot;
 
 uint8_t hmac_secret[8];
 randombytes(hmac_secret,sizeof(hmac_secret));
 
 /*:9*/
-#line 149 &quot;rwb0fuz1024.w&quot;
+#line 139 &quot;rwb0fuz1024.w&quot;
 
 /*10:*/
-#line 207 &quot;rwb0fuz1024.w&quot;
+#line 197 &quot;rwb0fuz1024.w&quot;
 
 memset(sk,0,SECRETKEYBYTES);
 mpz_export(sk,NULL,-1,8,-1,0,p);
@@ -241,10 +233,10 @@ memset(pk,0,PUBLICKEYBYTES);
 mpz_export(pk,NULL,-1,8,-1,0,n);
 
 /*:10*/
-#line 150 &quot;rwb0fuz1024.w&quot;
+#line 140 &quot;rwb0fuz1024.w&quot;
 
 /*11:*/
-#line 218 &quot;rwb0fuz1024.w&quot;
+#line 208 &quot;rwb0fuz1024.w&quot;
 
 mpz_clear(p);
 mpz_clear(q);
@@ -253,7 +245,7 @@ mpz_clear(u);
 mpz_clear(v);
 
 /*:11*/
-#line 151 &quot;rwb0fuz1024.w&quot;
+#line 141 &quot;rwb0fuz1024.w&quot;
 
 
 return 0;
@@ -267,10 +259,10 @@ return 0;
 #line 32 &quot;rwb0fuz1024.w&quot;
 
 /*13:*/
-#line 277 &quot;rwb0fuz1024.w&quot;
+#line 267 &quot;rwb0fuz1024.w&quot;
 
 /*26:*/
-#line 571 &quot;rwb0fuz1024.w&quot;
+#line 561 &quot;rwb0fuz1024.w&quot;
 
 static int
 is_quadratic_residue(mpz_t e,mpz_t p,mpz_t power){
@@ -292,10 +284,10 @@ return result;
 }
 
 /*:26*/
-#line 278 &quot;rwb0fuz1024.w&quot;
+#line 268 &quot;rwb0fuz1024.w&quot;
 
 /*28:*/
-#line 650 &quot;rwb0fuz1024.w&quot;
+#line 643 &quot;rwb0fuz1024.w&quot;
 
 static void
 signature_compress(mpz_t zsig,mpz_t s,mpz_t n){
@@ -338,10 +330,10 @@ mpz_clear(vs[3]);
 }
 
 /*:28*/
-#line 279 &quot;rwb0fuz1024.w&quot;
+#line 269 &quot;rwb0fuz1024.w&quot;
 
 /*14:*/
-#line 289 &quot;rwb0fuz1024.w&quot;
+#line 279 &quot;rwb0fuz1024.w&quot;
 
 int
 crypto_sign_rwb0fuz1024_gmp(uint8_t*sm,unsigned long long*smlen,
@@ -350,7 +342,7 @@ const uint8_t*sk){
 mpz_t p,q,u,v,n;
 
 /*15:*/
-#line 317 &quot;rwb0fuz1024.w&quot;
+#line 307 &quot;rwb0fuz1024.w&quot;
 
 mpz_init(p);
 mpz_init(q);
@@ -370,19 +362,19 @@ mpz_set_ui(v,1);
 mpz_sub(v,v,u);
 
 /*:15*/
-#line 296 &quot;rwb0fuz1024.w&quot;
+#line 286 &quot;rwb0fuz1024.w&quot;
 
 /*17:*/
-#line 387 &quot;rwb0fuz1024.w&quot;
+#line 377 &quot;rwb0fuz1024.w&quot;
 
 mpz_t elem;
 hash(elem,m,mlen);
 
 /*:17*/
-#line 297 &quot;rwb0fuz1024.w&quot;
+#line 287 &quot;rwb0fuz1024.w&quot;
 
 /*18:*/
-#line 399 &quot;rwb0fuz1024.w&quot;
+#line 389 &quot;rwb0fuz1024.w&quot;
 
 mpz_t pp1over4,qp1over4;
 
@@ -398,10 +390,10 @@ int a= is_quadratic_residue(elem,p,pp1over4);
 int b= is_quadratic_residue(elem,q,qp1over4);
 
 /*:18*/
-#line 298 &quot;rwb0fuz1024.w&quot;
+#line 288 &quot;rwb0fuz1024.w&quot;
 
 /*19:*/
-#line 441 &quot;rwb0fuz1024.w&quot;
+#line 431 &quot;rwb0fuz1024.w&quot;
 
 int mul_2= 0,negate= 0;
 
@@ -414,10 +406,10 @@ if(!a)
 negate= 1;
 
 /*:19*/
-#line 299 &quot;rwb0fuz1024.w&quot;
+#line 289 &quot;rwb0fuz1024.w&quot;
 
 /*20:*/
-#line 457 &quot;rwb0fuz1024.w&quot;
+#line 447 &quot;rwb0fuz1024.w&quot;
 
 if(negate)
 mpz_neg(elem,elem);
@@ -429,18 +421,18 @@ if(negate||mul_2)
 mpz_mod(elem,elem,n);
 
 /*:20*/
-#line 300 &quot;rwb0fuz1024.w&quot;
+#line 290 &quot;rwb0fuz1024.w&quot;
 
 /*21:*/
-#line 481 &quot;rwb0fuz1024.w&quot;
+#line 471 &quot;rwb0fuz1024.w&quot;
 
 const uint8_t r= HMAC_SHA512(sk+257,m,mlen);
 
 /*:21*/
-#line 301 &quot;rwb0fuz1024.w&quot;
+#line 291 &quot;rwb0fuz1024.w&quot;
 
 /*22:*/
-#line 504 &quot;rwb0fuz1024.w&quot;
+#line 494 &quot;rwb0fuz1024.w&quot;
 
 mpz_t proot,qroot;
 
@@ -461,19 +453,19 @@ mpz_add(proot,proot,qroot);
 mpz_mod(proot,proot,n);
 
 /*:22*/
-#line 302 &quot;rwb0fuz1024.w&quot;
+#line 292 &quot;rwb0fuz1024.w&quot;
 
 /*23:*/
-#line 527 &quot;rwb0fuz1024.w&quot;
+#line 517 &quot;rwb0fuz1024.w&quot;
 
 mpz_t zsig;
 signature_compress(zsig,proot,n);
 
 /*:23*/
-#line 303 &quot;rwb0fuz1024.w&quot;
+#line 293 &quot;rwb0fuz1024.w&quot;
 
 /*24:*/
-#line 539 &quot;rwb0fuz1024.w&quot;
+#line 529 &quot;rwb0fuz1024.w&quot;
 
 memset(sm,0,BYTES-1);
 sm[BYTES-1]= (mul_2&lt;&lt;1)|negate;
@@ -482,10 +474,10 @@ memcpy(sm+BYTES,m,mlen);
 *smlen= mlen+BYTES;
 
 /*:24*/
-#line 304 &quot;rwb0fuz1024.w&quot;
+#line 294 &quot;rwb0fuz1024.w&quot;
 
 /*25:*/
-#line 546 &quot;rwb0fuz1024.w&quot;
+#line 536 &quot;rwb0fuz1024.w&quot;
 
 mpz_clear(zsig);
 mpz_clear(n);
@@ -500,21 +492,21 @@ mpz_clear(p);
 mpz_clear(q);
 
 /*:25*/
-#line 305 &quot;rwb0fuz1024.w&quot;
+#line 295 &quot;rwb0fuz1024.w&quot;
 
 
 return 0;
 }
 
 /*:14*/
-#line 280 &quot;rwb0fuz1024.w&quot;
+#line 270 &quot;rwb0fuz1024.w&quot;
 
 
 /*:13*/
 #line 33 &quot;rwb0fuz1024.w&quot;
 
 /*29:*/
-#line 700 &quot;rwb0fuz1024.w&quot;
+#line 693 &quot;rwb0fuz1024.w&quot;
 
 int
 crypto_sign_rwb0fuz1024_gmp_open(unsigned char*m,unsigned long long*mlen,
@@ -523,7 +515,7 @@ const unsigned char*pk){
 int res= 0;
 
 /*30:*/
-#line 723 &quot;rwb0fuz1024.w&quot;
+#line 716 &quot;rwb0fuz1024.w&quot;
 
 if(smlen&lt;BYTES)
 return-1;
@@ -538,19 +530,19 @@ const uint8_t negate= sm[BYTES-1]&amp;1;
 const uint8_t mul_2= sm[BYTES-1]&amp;2;
 
 /*:30*/
-#line 707 &quot;rwb0fuz1024.w&quot;
+#line 700 &quot;rwb0fuz1024.w&quot;
 
 /*31:*/
-#line 736 &quot;rwb0fuz1024.w&quot;
+#line 729 &quot;rwb0fuz1024.w&quot;
 
 mpz_t elem;
 hash(elem,sm+BYTES,smlen-BYTES);
 
 /*:31*/
-#line 708 &quot;rwb0fuz1024.w&quot;
+#line 701 &quot;rwb0fuz1024.w&quot;
 
 /*20:*/
-#line 457 &quot;rwb0fuz1024.w&quot;
+#line 447 &quot;rwb0fuz1024.w&quot;
 
 if(negate)
 mpz_neg(elem,elem);
@@ -562,10 +554,10 @@ if(negate||mul_2)
 mpz_mod(elem,elem,n);
 
 /*:20*/
-#line 709 &quot;rwb0fuz1024.w&quot;
+#line 702 &quot;rwb0fuz1024.w&quot;
 
 /*32:*/
-#line 754 &quot;rwb0fuz1024.w&quot;
+#line 747 &quot;rwb0fuz1024.w&quot;
 
 mpz_mul(zsig,zsig,zsig);
 mpz_mul(zsig,zsig,elem);
@@ -582,7 +574,7 @@ goto out;
 }
 
 /*:32*/
-#line 710 &quot;rwb0fuz1024.w&quot;
+#line 703 &quot;rwb0fuz1024.w&quot;
 
 
 *mlen= smlen-BYTES;</diff>
      <filename>rwb0fuz1024.c</filename>
    </modified>
    <modified>
      <diff></diff>
      <filename>rwb0fuz1024.pdf</filename>
    </modified>
    <modified>
      <diff>@@ -761,4 +761,4 @@ uninteresting. Thus, we actually need only check that $t\ne 0$.
 
 @* Acknowledgements.
 
-Thanks to Daniel Bleichenbacher and Moti Yung for reviews and comments.
+Thanks to Daniel Bleichenbacher, Moti Yung and Matthew Dempsky for reviews and comments.</diff>
      <filename>rwb0fuz1024.w</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>db25c35ab3b3fdee33ebfb7d69f047c5b7f1e63a</id>
    </parent>
  </parents>
  <author>
    <name>Adam Langley</name>
    <email>agl@imperialviolet.org</email>
  </author>
  <url>http://github.com/agl/rwb0fuz1024/commit/fc234f11a75886afa8ed2a3f848991cfe770616f</url>
  <id>fc234f11a75886afa8ed2a3f848991cfe770616f</id>
  <committed-date>2008-10-09T09:17:50-07:00</committed-date>
  <authored-date>2008-10-09T09:17:50-07:00</authored-date>
  <message>Add a thanks to Matthew and update the derived sources</message>
  <tree>9b296f22b51e7c11f06e3dd8fcbb0ceac87ff8bc</tree>
  <committer>
    <name>Adam Langley</name>
    <email>agl@imperialviolet.org</email>
  </committer>
</commit>
