lib/ecdsa.c
// digital signature on message hash f, error bit d
digital signature on message hash f, error bit d
digital signature on message hash f error bit d
void ec_dsa(long f, long d, unsigned long *signature_buffer) {
  long i;
  long s;
  long t;
  pair sg;
  epnt W;
  t = (disc() == 0);
  t |= isO(e.G);
  pmul(&W, e.G, e.r);
  t |= !isO(W);
  t |= !ison(e.G);
  if (t) {
    goto errmsg;
  }
  printf("\n\tkey generation:");
  s = 1 + (long)(rnd() * (e.r - 1));
  pmul(&W, e.G, s);
  printf("\t\tprivate key s = %ld\n", s);
  pprint("\t\t\t\tpublic key W = sG", W);
  t = e.r;
  for (i = 1; i < 32; i <<= 1) {
    t |= t >> i;
  }
  while (f > t) {
    f >>= 1;
  }
  printf("\t\t\t\taligned hash: %ld\n", f);
  sg = signature(s, f);
  if (inverr) {
    goto errmsg;
  }
  printf("\t\t\t\tsignature c, d = %ld, %ld\n", sg.a, sg.b);
  if (d > 0) {
    while (d > t) {
      d >>= 1;
    }
    f ^= d;
    printf("\n\tcorrupted hash: %ld\n", f);
  }
  t = verify(W, f, sg);
  if (inverr) {
    goto errmsg;
  }
  if (t) {
    printf("\n\n\t\t\t\t\t  -----------\n\t\t\t\t\t     "
           "VALID\n\t\t\t\t\t  -------"
           "----\n");
    signature_buffer[0] = sg.a;
    signature_buffer[1] = sg.b;
  }
  else {
    printf("\n\n\t\t\t\t\t  -----------\n\t\t\t\t\t     "
           "INVALID\n\t\t\t\t\t  -----"
           "------\n");
  }
  return;
errmsg:
  printf("\n\t\t\t\t  ---------------------------");
  printf("\n\t\t\t\t     INVALID PARAMETER SET");
  printf("\n\t\t\t\t  ---------------------------\n");
}
void ec_dsa ( long f , long d , unsigned long * signature_buffer ) { long i ; long s ; long t ; pair sg ; epnt W ; t = ( disc ( ) == 0 ) ; t |= isO ( e . G ) ; pmul ( & W , e . G , e . r ) ; t |= ! isO ( W ) ; t |= ! ison ( e . G ) ; if ( t ) { goto errmsg ; } printf ( " \n \t " ) ; s = 1 + ( long ) ( rnd ( ) * ( e . r - 1 ) ) ; pmul ( & W , e . G , s ) ; printf ( " \t \t \n " , s ) ; pprint ( " \t \t \t \t " , W ) ; t = e . r ; for ( i = 1 ; i < 32 ; i <<= 1 ) { t |= t >> i ; } while ( f > t ) { f >>= 1 ; } printf ( " \t \t \t \t \n " , f ) ; sg = signature ( s , f ) ; if ( inverr ) { goto errmsg ; } printf ( " \t \t \t \t \n " , sg . a , sg . b ) ; if ( d > 0 ) { while ( d > t ) { d >>= 1 ; } f ^= d ; printf ( " \n \t \n " , f ) ; } t = verify ( W , f , sg ) ; if ( inverr ) { goto errmsg ; } if ( t ) { printf ( " \n \n \t \t \t \t \t \n \t \t \t \t \t " " \n \t \t \t \t \t " " \n " ) ; signature_buffer [ 0 ] = sg . a ; signature_buffer [ 1 ] = sg . b ; } else { printf ( " \n \n \t \t \t \t \t \n \t \t \t \t \t " " \n \t \t \t \t \t " " \n " ) ; } return ; errmsg : printf ( " \n \t \t \t \t " ) ; printf ( " \n \t \t \t \t " ) ; printf ( " \n \t \t \t \t \n " ) ; }
digital signature on message hash f, error bit d
digital signature on message hash f error bit d
// parameter check // next highest power of 2 - 1