Пример #1
0
/**
 * cdk_keygen_set_algo_info: set the length and type of the key
 * @hd: the keygen object.
 * @type: key type (primary=0, subkey=1)
 * @algo: algorithm compliant with rfc2440
 * @bits: lengt of the key in bits
 *
 **/
cdk_error_t
cdk_keygen_set_algo_info( cdk_keygen_ctx_t hd, int type,
                          enum cdk_pk_algo_t algo, int bits )
{
    int rc;
    int usage = type? PK_USAGE_ENCR : PK_USAGE_SIGN;
  
    if( !hd )
        return CDK_Inv_Value;
    if( type < 0 || type > 1 )
        return CDK_Inv_Value;

    if( bits % 128 != 0 )
        bits = bits + ( bits % 128 );
  
    rc = _cdk_pk_test_algo( algo, usage );
    if( rc )
        return rc;

    /* type=0 primary type=1 sub */
    hd->key[type].algo = algo;
    hd->key[type].len = check_bits( bits, algo );

    return 0;
}
Пример #2
0
void fix_bit(int correct){
    
    int nowfor=0;
    
    check_bits(nowfor+1, correct, 0);
    
    
}
Пример #3
0
int main(int argc, char **argv) {
    if (argc != 4) {
        printUsage();
    }
    
    int number = atoi(argv[1]);
    int pos_1 = atoi(argv[2]);
    int pos_2 = atoi(argv[3]);
    char *pointer = dec_to_bin(number);

    int check = check_bits(pointer, pos_1, pos_2);
    print_match(check);

    free(pointer);
    return 0;
}
Пример #4
0
void check_bits(int nowfor, int correct, int befornum){
    char tmp[MBITS+1];
    for (int tmpcount=0; tmpcount<MBITS; tmpcount++){tmp[tmpcount]=answer[tmpcount];}
    for (int b = befornum; b<MBITS; b++) {
        answer[b]=input[b];
        if (nowfor==correct) {
            for (int count=0; count<MBITS; count++) {
                if (answer[count]=='\0') {
                    answer[count]=changechar(input[count]);
                }
            }
            printf("%s\n",answer);
            for (int tmpcount=0; tmpcount<MBITS; tmpcount++){answer[tmpcount]=tmp[tmpcount];}
        } else {
            check_bits(nowfor+1, correct, b+1);
            for (int tmpcount=0; tmpcount<MBITS; tmpcount++){answer[tmpcount]=tmp[tmpcount];}
        }
    }
    
}
Пример #5
0
static void
test_behavior ()
{
    union {
        float       f;
        double      d;

#ifndef _RWSTD_NO_LONG_DOUBLE
        long double l;
#endif   // _RWSTD_NO_LONG_DOUBLE

        char buf [sizeof (long double) * 2];
    } u;

#if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    // make sure functions do not overflow buffer
    clear_bytes (u.buf, sizeof u);
    const float f = std::modf (3.141592f, &u.f);
    if(!( 3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof u.f, sizeof u - sizeof u.f))) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
  
      rw_assert (   3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof u.f, sizeof u - sizeof u.f),
               0, __LINE__, "float std::modf (float)");

#endif   // SunPro > 5.3

    clear_bytes (u.buf, sizeof u);
    const double d = std::modf (3.1415926, &u.d);
    
    if(!(3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof u.d, sizeof u - sizeof u.d))) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
    rw_assert (   3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof u.d, sizeof u - sizeof u.d),
               0, __LINE__, "double std::modf (double)");

#ifndef __SYMBIAN32__
#ifndef _RWSTD_NO_LONG_DOUBLE

#  if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    clear_bytes (u.buf, sizeof u);
    const long double l = std::modf (3.1415926L, &u.l);
     bool test=check_bits (u.buf + sizeof u.l, sizeof u - sizeof u.l);
     if(!(3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && test)) 
     {
       failures++;
       std_log(LOG_FILENAME_LINE,"Reason: Failing modf function");
      }
    rw_assert (   3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && check_bits (u.buf + sizeof u.l, sizeof u - sizeof u.l),
               0, __LINE__, "long double std::modf (long double)");

#  endif   // SunPro > 5.3

#endif   // _RWSTD_NO_LONG_DOUBLE
#endif // __SYMBIAN32__


    // check overloads of std::pow()
    for (int i = -10; i != 10; ++i) {
        for (int j = -10; j != 10; ++j) {

            if (-9 < j && j < 9) {
                // verify that both versions are equivalent
                const float xf = std::pow (float (i), int (j));
                const float yf = std::pow (float (i), float (j));
                       
                 if(!(rw_equal (xf, yf) || !i && j < 0))
                 {
                   failures++;
                   std_log(LOG_FILENAME_LINE,"Reason: Failing pow function for i=%d,j=%d",i,j);
                 }
                  
                rw_assert (rw_equal (xf, yf) || !i && j < 0,
                           0, __LINE__,
                           "std::pow (%d.0f, %d) = %g, "
                           "std::pow (%d,0f, %d.0f) = %g",
                           i, j, xf, i, j, yf);
            }

            const float xd = std::pow (double (i), int (j));
            const float yd = std::pow (double (i), double (j));

			  if(!(rw_equal (xd, yd) || !i && j < 0))
			                 {
			                   failures++;
			                    std_log(LOG_FILENAME_LINE,"Reason: Failing pow function for i=%d,j=%d",i,j);
			                 }

            rw_assert (rw_equal (xd, yd) || !i && j < 0,
                       0, __LINE__,
                       "std::pow (%d.0, %d) = %g, "
                       "std::pow (%d.0, %d.0) = %g",
                       i, j, xd, i, j, yd);

#ifndef _RWSTD_NO_LONG_DOUBLE

            const long double xl = std::pow ((long double)i, int (j));
            const long double yl = std::pow ((long double)i, (long double)j);
            
            if(!(rw_equal (xl, yl) || !i && j < 0))
			                 {
			                   failures++;
			                    std_log(LOG_FILENAME_LINE,"Reason: Failing pow function ");
			                 }

        
            rw_assert (rw_equal (xl, yl) || !i && j < 0,
                       0, __LINE__,
                       "std::pow (%d.0L, %d) = %Lg, "
                       "std::pow (%d.0L, %d.0L) = %Lg",
                       i, j, xl, i, j, yl);

#endif   // _RWSTD_NO_LONG_DOUBLE

        }
    }
}
Пример #6
0
int main(int argc, char** argv)
{
  int offset, padding;
  int width, logn, maxlogn;
  qio_chtype_t type;
  qio_hint_t hints[] = {QIO_METHOD_DEFAULT, QIO_METHOD_READWRITE, QIO_METHOD_PREADPWRITE, QIO_METHOD_FREADFWRITE, QIO_METHOD_MEMORY, QIO_METHOD_MMAP, QIO_METHOD_MMAP|QIO_HINT_PARALLEL, QIO_METHOD_PREADPWRITE | QIO_HINT_NOFAST};
  int nhints = sizeof(hints)/sizeof(qio_hint_t);
  int file_hint, ch_hint;

  {
    //for( file_hint = 0; file_hint < nhints; file_hint++ ) {
    //  check_write_read_pat(1, 262144, 0, 0, file_hint, file_hint, 0);
    //}

    //check_write_read_pat(32,4096,0,3,QIO_METHOD_PREADPWRITE,0,1);
    //check_write_read_pat(32,4096,0,3,0,0,1);
    //exit(0);
//check_write_read_pat(width=32, num=4096, pat=0, type=3, file_hints=default_type default, ch_hints=buffered default, reopen=1)

    // Run unit tests.
    for( offset = 0; offset < 63; offset++ ) {
      for( padding = 0; padding < 63; padding++ ) {
        check_bits(offset, padding);
      }
    }

    maxlogn = 19;
    if( valgrind ) maxlogn = 10;

    for( logn = 0; logn < maxlogn; logn+=9 ) {
      for( width = 1; width <= 64; width++ ) {
        for( file_hint = 0; file_hint < nhints; file_hint++ ) {
          ch_hint = file_hint;
          type = 0;
          check_write_read_pat(width,1 << logn,0,type,file_hint,ch_hint,0);
          check_write_read_pat(width,1 << logn,1,type,file_hint,ch_hint,1);
        }
      }
    }
  }

  // Do extra testing that showed a bug at one point...
  if( !valgrind ) {

    int i;
    int n = 256*1024*1024;

    qio_file_t* f;
    qio_channel_t* writing;
    qio_channel_t* reading;
    uint64_t got;
    uint64_t expect;
    qioerr err;
    

    //qbytes_iobuf_size = 256;

    err = qio_file_open_mem(&f, NULL, NULL);
    assert(!err);
    //err = qio_file_open_access(&f, "test.bin", "w+", 0, NULL);
    //assert(!err);

    err = qio_channel_create(&writing, f, 0, 0, 1, 0, INT64_MAX, NULL);
    assert(!err);

    for( i = 0; i < n; i++ ) {
      err = qio_channel_write_bits(false, writing, i & 0x1f, 5);
      //err = qio_channel_write_bits(false, writing, 0x1f, 5);
      assert(!err);
    }

    qio_channel_release(writing);

    if( argc > 2 ) {
      err = qio_channel_create(&reading, f, 0, 1, 0, 0, INT64_MAX, NULL);
      assert(!err);

      for( i = 0; i < n; i++ ) {
        got = 0;
        err = qio_channel_read_bits(false, reading, &got, 5);
        assert(!err);
        expect = i & 0x1f;
        //expect = 0x1f;
        if( got != expect ) {
          printf("Failed at i=%i got %llx expect %llx\n", i, (long long int) got, (long long int) expect);
          assert( got == expect );
        }
      }

      qio_channel_release(reading);
    }

    qio_file_release(f);
  }

  printf("qio_bits_test PASS\n");

  return 0;
}
Пример #7
0
/*-
 * _gnutls_x509_cert_verify_peers - return the peer's certificate status
 * @session: is a gnutls session
 *
 * This function will try to verify the peer's certificate and return its status (TRUSTED, REVOKED etc.).
 * The return value (status) should be one of the gnutls_certificate_status_t enumerated elements.
 * However you must also check the peer's name in order to check if the verified certificate belongs to the
 * actual peer. Returns a negative error code in case of an error, or GNUTLS_E_NO_CERTIFICATE_FOUND if no certificate was sent.
 -*/
int
_gnutls_x509_cert_verify_peers (gnutls_session_t session,
				unsigned int *status)
{
  cert_auth_info_t info;
  gnutls_certificate_credentials_t cred;
  gnutls_x509_crt_t *peer_certificate_list;
  int peer_certificate_list_size, i, x, ret;

  CHECK_AUTH (GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);

  info = _gnutls_get_auth_info (session);
  if (info == NULL)
    {
      gnutls_assert ();
      return GNUTLS_E_INVALID_REQUEST;
    }

  cred = (gnutls_certificate_credentials_t)
    _gnutls_get_cred (session->key, GNUTLS_CRD_CERTIFICATE, NULL);
  if (cred == NULL)
    {
      gnutls_assert ();
      return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
    }

  if (info->raw_certificate_list == NULL || info->ncerts == 0)
    return GNUTLS_E_NO_CERTIFICATE_FOUND;

  if (info->ncerts > cred->verify_depth && cred->verify_depth > 0)
    {
      gnutls_assert ();
      return GNUTLS_E_CONSTRAINT_ERROR;
    }

  /* generate a list of gnutls_certs based on the auth info
   * raw certs.
   */
  peer_certificate_list_size = info->ncerts;
  peer_certificate_list =
    gnutls_calloc (peer_certificate_list_size, sizeof (gnutls_x509_crt_t));
  if (peer_certificate_list == NULL)
    {
      gnutls_assert ();
      return GNUTLS_E_MEMORY_ERROR;
    }

  for (i = 0; i < peer_certificate_list_size; i++)
    {
      ret = gnutls_x509_crt_init (&peer_certificate_list[i]);
      if (ret < 0)
	{
	  gnutls_assert ();
	  CLEAR_CERTS;
	  return ret;
	}

      ret =
	gnutls_x509_crt_import (peer_certificate_list[i],
				&info->raw_certificate_list[i],
				GNUTLS_X509_FMT_DER);
      if (ret < 0)
	{
	  gnutls_assert ();
	  CLEAR_CERTS;
	  return ret;
	}


      if (ret < 0)
	{
	  gnutls_assert ();
	  CLEAR_CERTS;
	  return ret;
	}

      ret = check_bits (peer_certificate_list[i], cred->verify_bits);
      if (ret < 0)
	{
	  gnutls_assert ();
	  CLEAR_CERTS;
	  return ret;
	}

    }

  /* Verify certificate 
   */

  ret = gnutls_x509_crt_list_verify (peer_certificate_list,
				     peer_certificate_list_size,
				     cred->x509_ca_list, cred->x509_ncas,
				     cred->x509_crl_list, cred->x509_ncrls,
				     cred->verify_flags | session->internals.
				     priorities.additional_verify_flags,
				     status);

  CLEAR_CERTS;

  if (ret < 0)
    {
      gnutls_assert ();
      return ret;
    }

  return 0;
}
Пример #8
0
static void
test_behavior ()
{
    union {
        float       f;
        double      d;

#ifndef _RWSTD_NO_LONG_DOUBLE
        long double l;
#endif   // _RWSTD_NO_LONG_DOUBLE

        char buf [sizeof (long double) * 2];
    } u;

#if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    // make sure functions do not overflow buffer
    clear_bytes (u.buf, sizeof u);

    const float f = std::modf (3.141592f, &u.f);

    rw_assert (   3000 == int (u.f * 1000) && 141592 == int (f * 1000000)
               && check_bits (u.buf + sizeof (u.f), sizeof (u) - sizeof (u.f)),
               __FILE__, __LINE__, "float std::modf (float)");

#endif   // SunPro > 5.3

    clear_bytes (u.buf, sizeof u);
    const double d = std::modf (3.1415926, &u.d);

    rw_assert (   3000 == int (u.d * 1000) && 1415926 == int (d * 10000000)
               && check_bits (u.buf + sizeof (u.d), sizeof (u) - sizeof (u.d)),
               __FILE__, __LINE__, "double std::modf (double)");

#ifndef _RWSTD_NO_LONG_DOUBLE

#  if !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x530

    clear_bytes (u.buf, sizeof u);
    const long double l = std::modf (3.1415926L, &u.l);

    rw_assert (   3000 == int (u.l * 1000) && 1415926 == int (l * 10000000)
               && check_bits (u.buf + sizeof (u.l), sizeof (u) - sizeof (u.l)),
               __FILE__, __LINE__, "long double std::modf (long double)");

#  endif   // SunPro > 5.3

#endif   // _RWSTD_NO_LONG_DOUBLE

    // check overloads of std::pow()
    for (int i = -10; i != 10; ++i) {

        for (int j = -10; j != 10; ++j) {

            if (-9 < j && j < 9) {
                const float fi = float (i);
                const float fj = float (j);

                // verify that both versions are equivalent
                const float xf = std::pow (fi, j);
                const float yf = std::pow (fi, fj);

                rw_assert (rw_equal (xf, yf) || (!i && j < 0),
                           0, __LINE__,
                           "std::pow (%d.0f, %d) = %g, "
                           "std::pow (%d,0f, %d.0f) = %g",
                           i, j, xf, i, j, yf);
            }

            const double id = double (i);
            const double jd = double (j);

            const double xd = std::pow (id, j);
            const double yd = std::pow (id, jd);

            rw_assert (rw_equal (xd, yd) || (!i && j < 0),
                       0, __LINE__,
                       "std::pow (%d.0, %d) = %g, "
                       "std::pow (%d.0, %d.0) = %g",
                       i, j, xd, i, j, yd);

#ifndef _RWSTD_NO_LONG_DOUBLE

            const long double il = _RWSTD_STATIC_CAST (long double, i);
            const long double jl = _RWSTD_STATIC_CAST (long double, j);

            const long double xl = std::pow (il, j);
            const long double yl = std::pow (il, jl);

            rw_assert (rw_equal (xl, yl) || (!i && j < 0),
                       0, __LINE__,
                       "std::pow (%d.0L, %d) = %Lg, "
                       "std::pow (%d.0L, %d.0L) = %Lg",
                       i, j, xl, i, j, yl);

#endif   // _RWSTD_NO_LONG_DOUBLE

        }
    }
}