Esempio n. 1
0
bool CryptoHash::Digest(
    const HashType hashType,
    const String& data,
    OTData& digest)
{
    OTData plaintext(data.Get(), data.GetLength());

    return Digest(hashType, plaintext, digest);
}
Esempio n. 2
0
    Digest Buffer::getCRC64() const
    {
        unsigned char digest[8]={0};
        CRC64Context context;

        CRC64Reset(&context);
        CRC64Input(&context, (unsigned char *)m_data, m_length);
        CRC64Result(&context, digest);

        return Digest(digest,8);
    }
Esempio n. 3
0
    Digest Buffer::getSHA512() const
    {
        unsigned char digest[64]={0};
        SHA512_CTX context;

        SHA512_Init(&context);
        SHA512_Update(&context, (unsigned char *)m_data, m_length);
        SHA512_Final(digest, &context);

        return Digest(digest,64);
    }
Esempio n. 4
0
    Digest Buffer::getSHA384() const
    {
        unsigned char digest[48]={0};
        SHA384_CTX context;

        SHA384_Init(&context);
        SHA384_Update(&context, (unsigned char *)m_data, m_length);
        SHA384_Final(digest, &context);

        return Digest(digest,48);
    }
Esempio n. 5
0
    Digest Buffer::getSHA256() const
    {
        unsigned char digest[32]={0};
        SHA256_CTX context;

        SHA256_Init(&context);
        SHA256_Update(&context, (unsigned char *)m_data, m_length);
        SHA256_Final(digest, &context);

        return Digest(digest,32);
    }
Esempio n. 6
0
    Digest Buffer::getSHA1() const
    {
        unsigned char digest[20]={0};
        SHA1Context context;

        SHA1Reset(&context);
        SHA1Input(&context, (unsigned char *)m_data, m_length);
        SHA1Result(&context, digest);

        return Digest(digest,20);
    }
Esempio n. 7
0
    Digest Buffer::getMD5() const
    {
        unsigned char digest[16]={0};
        MD5_CTX context;

        MD5Init(&context);
        MD5Update(&context, (unsigned char *)m_data, m_length);
        MD5Final(digest,&context);

        return Digest(digest,16);
    }
/*
 * AddPassword: Prompts the user for a password
 *              and adds the entry in the file
 *              user:crpytofpassword:md5hash(user:realm:password) 
 */
static void AddPassword(char *user, char* realm, FILE *f)
{
    char *pw, *crpw, cpw[120], salt[9], *dpw;
    int len = 0, i = 0, crpwLen = 0;
    char *checkw;

    pw = CopyString((char *) getpass("New password:"******"Password cannot be blank, sorry.\n");
        delete(checkw);
        CleanupAndExit();
    }
    delete(checkw);
    
    if (strcmp(pw, (char *) getpass("Re-type new password:"******"They don't match, sorry.\n");
		CleanupAndExit();
    }
	
    (void) srand((int) time((time_t *) NULL));
    to64(&salt[0], rand(), 8);
    salt[8] = '\0';

#ifdef __Win32__
    MD5Encode((char *)pw, (char *)salt, cpw, sizeof(cpw));
#else
    crpw = (char *)crypt(pw, salt); // cpw is crypt of password
    crpwLen = ::strlen(crpw);
    strncpy(cpw, crpw, crpwLen);
    cpw[crpwLen] = '\0';
#endif
    
    dpw = (char *)Digest(user, pw, realm); // dpw is digest of password
    
    qtss_fprintf(f, "%s:%s:%s\n", user, cpw, dpw);
    free(pw); // Do after cpw and dpw are used. 
}
Esempio n. 9
0
bool CryptoHash::Digest(
    const uint32_t type,
    const std::string& data,
    std::string& encodedDigest)
{
    OTData plaintext(data.c_str(), data.size());
    OTData result;

    bool success = Digest(
        static_cast<CryptoHash::HashType>(type),
        plaintext,
        result);

    if (success) {
        encodedDigest.assign(
            App::Me().Crypto().Util().Base58CheckEncode(result).Get());
    }

    return success;
}
/*
 * AddPasswordWithoutPrompt:    Adds the entry in the file
 *                              user:crpytofpassword:md5hash(user:realm:password) 
 */
static void AddPasswordWithoutPrompt(char *user, char* password, char* realm, FILE *f)
{
    char salt[9];

    (void) srand((int) time((time_t *) NULL));
    to64(&salt[0], rand(), 8);
    salt[8] = '\0';

    char cpw[120], *dpw;
    int crpwLen = 0;

#ifdef __Win32__
    MD5Encode((char *)password, (char *)salt, cpw, sizeof(cpw));
#else
    char *crpw = (char *)crypt(password, salt); // cpw is crypt of password
    crpwLen = ::strlen(crpw);
    strncpy(cpw, crpw, crpwLen);
    cpw[crpwLen] = '\0';
#endif
    
    dpw = (char *)Digest(user, password, realm); // dpw is digest of password
    
    qtss_fprintf(f, "%s:%s:%s\n", user, cpw, dpw);
}
Esempio n. 11
0
/* dotablefilter()
 *
 *
 *
 *
 */
static int32_t dotablefilter (CSOUND *csound, TABFILT *p)
{
    int32 loopcount;     /* Loop counter. Set by the length of the dest table.*/
    int32 indx = 0;              /* Index to be added to offsets */
    int32 indx2 = 0; /*index into source table*/
    MYFLT *based, *bases;       /* Base addresses of the two tables.*/
    int32 masks;                 /* Binary masks for the source table */
    MYFLT *pdest, *ps;
    MYFLT threshold;
    int32 ftype;
    MYFLT previous = FL(0.0);
    //int32 sourcelength;

    ftype = (int32) *p->ftype;
    threshold = Digest (*p->threshold);
    loopcount = p->funcd->flen;
    //sourcelength = loopcount;

    /* Now get the base addresses and length masks of the tables. */
    based  = p->funcd->ftable;
    bases = p->funcs->ftable;
    masks = p->funcs->lenmask;

    do {
      /* Create source pointers by ANDing index with mask, and adding to base
       * address. This causes source  addresses to wrap around if the
       * destination table is longer.
       * Destination address is simply the index plus the base address since
       * we know we will be writing within the table.          */

      pdest = based  + indx;
      ps    = bases  + (masks & indx2);
      switch (ftype) {
      default:
      case 0:
        *pdest = *ps;
        indx++; indx2++;
        break;
      case 1:
        { /* filter all above threshold */
          int32_t p, q = 0;
          float2frac (csound, *ps, &p, &q);
          if (Digest (q) > threshold) {
            indx2++;
          } else {
            *pdest = *ps;
            indx++; indx2++;
          }
          break;
        }
      case 2:
        { /* filter all below threshold */
          int32_t p, q = 0;
          float2frac (csound, *ps, &p, &q);
          if (Digest (q) < threshold) {
            indx2++;
          } else {
            *pdest = *ps;
            indx++; indx2++;
          }
          break;
        }
      case 3:
        { /* generate IOIs from source and write into destination */
          if (*ps == FL(0.0)) { /* skip zeros in source table */
            indx2++;
            break;
          }
          *pdest = *ps - previous;
          previous = *ps;
          indx++; indx2++;
          break;
        }
      }
    } while (--loopcount);

    *p->result = indx;

    return OK;
}
Esempio n. 12
0
Digest PadderReal::pad( Digest digest, Size target_size, Monitor& monitor )
{
	if (!monitor) return Digest();
	//TODO:
	throw std::runtime_error("Not Implemented");
}
Esempio n. 13
0
Cmd5Capi::Cmd5Capi(CString & csBuffer)
{
	Digest(csBuffer);
}
Esempio n. 14
0
void CogGaze::Apply(JointPos& joints)
{
  HeadState state;
  JointPos& datum = joints;
  state.SetEyes(datum(1), datum(2), datum(3));
  state.SetNeck(datum(4), datum(5), datum(7), datum(6));

  // gyro reported orientation applies to origin point p_origin
  // right between the eyes, fixed wrt head.
  
  double tilt_ticks_per_right_angle = 24371;
  double left_pan_ticks_per_right_angle = 42791;
  double right_pan_ticks_per_right_angle = 44238;
  double neck_lean_ticks_per_right_angle = 25657;
  double neck_pan_ticks_per_right_angle = 49549;
  double neck_tilt_ticks_per_right_angle = 36335;
  double neck_roll_ticks_per_right_angle = 38025;
  
  double rads_per_right_angle = M_PI/2;
  double tilt_ticks_per_rad = tilt_ticks_per_right_angle/rads_per_right_angle;
  double left_pan_ticks_per_rad = left_pan_ticks_per_right_angle/rads_per_right_angle;
  double right_pan_ticks_per_rad = right_pan_ticks_per_right_angle/rads_per_right_angle;
  double neck_lean_ticks_per_rad = neck_lean_ticks_per_right_angle/rads_per_right_angle;
  double neck_pan_ticks_per_rad = neck_pan_ticks_per_right_angle/rads_per_right_angle;
  double neck_roll_ticks_per_rad = neck_roll_ticks_per_right_angle/rads_per_right_angle;
  double neck_tilt_ticks_per_rad = neck_tilt_ticks_per_right_angle/rads_per_right_angle;
  
  double deg = 180.0/M_PI;
  
  double lean_ref = -10000;
  double tilt_ref = -14000;
  
#if 0
  printf("gyro %g %g %g || eye %g %g %g || neck %g %g %g %g || ",
	 state.yaw/M_PI*180, state.pitch/M_PI*180, state.roll/M_PI*180,
	 state.tilt, state.left_pan, state.right_pan,
	 state.neck_lean, state.neck_pan, state.neck_tilt,
	 state.neck_roll);
  //#else
  printf("gyro %.1f %.1f %.1f || eye %.1f %.1f %.1f || neck %.1f %.1f %.1f %.1f || ",
	 state.yaw/M_PI*180, state.pitch/M_PI*180, state.roll/M_PI*180,
	 state.tilt*deg/tilt_ticks_per_rad, 
	 state.left_pan*deg/left_pan_ticks_per_rad, 
	 state.right_pan*deg/right_pan_ticks_per_rad,
	 (state.neck_lean-lean_ref)*deg/neck_lean_ticks_per_rad, 
	 state.neck_pan*deg/neck_pan_ticks_per_rad, 
	 (state.neck_tilt-tilt_ref)*deg/neck_tilt_ticks_per_rad,
	 state.neck_roll*deg/neck_roll_ticks_per_rad);
#endif	  
  
  
  Matrix m(4,4);
  // using homogeneous matrices; don't actually need to
  // since we just care about rotations in this case
  
  // A rotation about the y axis, for panning (left)
  double left_pan_angle = state.left_pan / left_pan_ticks_per_rad;
  double c = cos(left_pan_angle);
  double s = sin(left_pan_angle);
  m[0][0] = c;  m[0][1] = 0;  m[0][2] = s;  m[0][3] = 0; 
  m[1][0] = 0;  m[1][1] = 1;  m[1][2] = 0;  m[1][3] = 0;
  m[2][0] =-s;  m[2][1] = 0;  m[2][2] = c;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_left_pan = m;
  
  // A rotation about the y axis, for panning (right)
  double right_pan_angle = state.right_pan/right_pan_ticks_per_rad;
  c = cos(right_pan_angle);
  s = sin(right_pan_angle);
  m[0][0] = c;  m[0][1] = 0;  m[0][2] = s;  m[0][3] = 0;
  m[1][0] = 0;  m[1][1] = 1;  m[1][2] = 0;  m[1][3] = 0;
  m[2][0] =-s;  m[2][1] = 0;  m[2][2] = c;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_right_pan = m;
  
  // A rotation about the x axis, for tilting
  double tilt_angle = state.tilt/tilt_ticks_per_rad;
  c = cos(tilt_angle);
  s = sin(tilt_angle);
  m[0][0] = 1;  m[0][1] = 0;  m[0][2] = 0;  m[0][3] = 0;
  m[1][0] = 0;  m[1][1] = c;  m[1][2] =-s;  m[1][3] = 0;
  m[2][0] = 0;  m[2][1] = s;  m[2][2] = c;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_tilt = m;
  
  // A rotation about the z axis, for neck_roll
  double roll_angle = -state.neck_roll/neck_roll_ticks_per_rad;
  c = cos(roll_angle);
  s = sin(roll_angle);
  m[0][0] = c;  m[0][1] =-s;  m[0][2] = 0;  m[0][3] = 0;
  m[1][0] = s;  m[1][1] = c;  m[1][2] = 0;  m[1][3] = 0;
  m[2][0] = 0;  m[2][1] = 0;  m[2][2] = 1;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_neck_roll = m;
  
  // A rotation about the x axis, for neck_tilt
  // This axis is the only one whose "resting" position is very 
  // far from neutral -- need to check with pasa where calibration
  // puts the zero point, assuming for now that it is orthogonal
  // to gravity vector
  double neck_tilt_angle_offset = M_PI/2;
  double neck_tilt_angle = -(state.neck_tilt-tilt_ref)/neck_tilt_ticks_per_rad;
  neck_tilt_angle += neck_tilt_angle_offset;
  c = cos(neck_tilt_angle);
  s = sin(neck_tilt_angle);
  m[0][0] = 1;  m[0][1] = 0;  m[0][2] = 0;  m[0][3] = 0;
  m[1][0] = 0;  m[1][1] = c;  m[1][2] =-s;  m[1][3] = 0;
  m[2][0] = 0;  m[2][1] = s;  m[2][2] = c;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_neck_tilt = m;
  
  
  /*
   // A rotation about the y axis, for neck_pan
   double neck_pan_angle = -state.neck_pan/neck_pan_ticks_per_rad;
   c = cos(neck_pan_angle);
   s = sin(neck_pan_angle);
   m[0][0] = c;  m[0][1] = 0;  m[0][2] = s;  m[0][3] = 0;
   m[1][0] = 0;  m[1][1] = 1;  m[1][2] = 0;  m[1][3] = 0;
   m[2][0] =-s;  m[2][1] = 0;  m[2][2] = c;  m[2][3] = 0;
   m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
   Matrix m_neck_pan = m;
   */
  
  // A rotation about the z axis, for neck_pan (actually a roll)
  double neck_pan_angle = -state.neck_pan/neck_pan_ticks_per_rad;
  c = cos(neck_pan_angle);
  s = sin(neck_pan_angle);
  m[0][0] = c;  m[0][1] =-s;  m[0][2] = 0;  m[0][3] = 0;
  m[1][0] = s;  m[1][1] = c;  m[1][2] = 0;  m[1][3] = 0;
  m[2][0] = 0;  m[2][1] = 0;  m[2][2] = 1;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_neck_pan = m;
  
  // A rotation about the x axis, for neck_lean
  // neck_lean zero point -10000
  double neck_lean_angle = (state.neck_lean-lean_ref)/neck_lean_ticks_per_rad;
  c = cos(neck_lean_angle);
  s = sin(neck_lean_angle);
  m[0][0] = 1;  m[0][1] = 0;  m[0][2] = 0;  m[0][3] = 0;
  m[1][0] = 0;  m[1][1] = c;  m[1][2] =-s;  m[1][3] = 0;
  m[2][0] = 0;  m[2][1] = s;  m[2][2] = c;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_neck_lean = m;
  
  /*
  // Rotation corresponding to yaw, pitch, and roll
  double y = state.yaw, p = state.pitch, r = state.roll;
  double cosp = cos(p), sinp = sin(p);
  double cosy = cos(y), siny = sin(y);
  double cosr = cos(r), sinr = sin(r);
  m[0][0] = cosp*cosy;  m[0][1] = sinr*sinp*cosy-cosr*siny; 
  m[0][2] = cosr*sinp*cosy+sinr*siny;  m[0][3] = 0;
  m[1][0] = cosp*siny;  m[1][1] = sinr*sinp*siny+cosr*cosy;  
  m[1][2] = cosr*sinp*siny-sinr*cosy;  m[1][3] = 0;
  m[2][0] = -sinp;  m[2][1] = cosp*sinr;  
  m[2][2] = cosp*cosr;  m[2][3] = 0;
  m[3][0] = 0;  m[3][1] = 0;  m[3][2] = 0;  m[3][3] = 1;
  Matrix m_euler = m;
  
  Matrix m_left = m_euler * m_tilt * m_left_pan;
  Matrix m_right = m_euler * m_tilt * m_right_pan;
   */
  
  // Consider a vector pointing out from camera
  Matrix m_common = m_neck_lean * m_neck_pan * m_neck_tilt * m_neck_roll * m_tilt;
  Matrix m_left_all = m_common * m_left_pan;
  Matrix m_right_all = m_common * m_right_pan;
  
  CogGaze& dir = *this;
  for (int i=0; i<3; i++)
    {
      dir.x_left[i] = m_left_all[i][0];
      dir.y_left[i] = m_left_all[i][1];
      dir.z_left[i] = m_left_all[i][2];
      dir.x_right[i] = m_right_all[i][0];
      dir.y_right[i] = m_right_all[i][1];
      dir.z_right[i] = m_right_all[i][2];
    }
  

  Digest(m_left_all,dir.theta_left,dir.phi_left,dir.roll_left);
  Digest(m_right_all,dir.theta_right,dir.phi_right,dir.roll_right);
	  
  printf("LEFT %+8.2f %+8.2f %+8.2f      RIGHT %+8.2f %+8.2f %+8.2f\n", 
	 dir.theta_left*180.0/M_PI, 
	 dir.phi_left*180.0/M_PI,
	 dir.roll_left*180.0/M_PI,
	 dir.theta_right*180.0/M_PI, 
	 dir.phi_right*180.0/M_PI,
	 dir.roll_right*180.0/M_PI);
}