bool CvSakke::DecodePublicParams( const String& aPublicParams, OUT octet& aPx, OUT octet& aPy ) { CvString publicParams = aPublicParams; vector<CvString> tokens; publicParams.Tokenize( "#", tokens ); if ( tokens.size() != 2 ) return false; tokens[0].TrimLeft("["); tokens[0].TrimRight("]"); vector<CvString> tokensP; tokens[0].Tokenize( ",", tokensP ); if ( tokensP.size() != 2 ) return false; String decoded; CvBase64::Decode( tokensP[0], decoded ); OCTET_JOIN_BYTES( decoded.data(), (int)decoded.size(), &aPx ); decoded.clear(); CvBase64::Decode( tokensP[1], decoded ); OCTET_JOIN_BYTES( decoded.data(), (int)decoded.size(), &aPy ); return true; }
bool CvSakke::DecodeEncapsulatedData( const String& aEncapsulatedData, OUT octet& aRbS, OUT octet& aH ) { OCTET_CLEAR(&aRbS); OCTET_CLEAR(&aH); CvString encapsulatedData = aEncapsulatedData; vector<CvString> tokens; encapsulatedData.Tokenize( ",", tokens ); if ( tokens.size() != 2 ) return false; String decoded; CvBase64::Decode( tokens[0], decoded ); if ( decoded.size() != aH.max ) return false; OCTET_JOIN_BYTES( decoded.data(), aH.max, &aH ); decoded.clear(); CvBase64::Decode( tokens[1], decoded ); if ( decoded.size() != aRbS.max ) return false; OCTET_JOIN_BYTES( decoded.data(), aRbS.max, &aRbS ); return true; }
/* CDpkgConfig* CvSakke::GetSakkeParams() //temporary { return CDpkgConfig::Instance(); } */ bool CvSakke::DecodePublicKey( const String& aPublicKey, OUT octet& aZ_S ) { OCTET_CLEAR(&aZ_S); if ( aPublicKey[0] != '[' || aPublicKey[aPublicKey.length()-1] != ']' ) return false; CvString publicKey = aPublicKey; publicKey.TrimLeft( "[" ); publicKey.TrimRight( "]" ); vector<CvString> tokens; publicKey.Tokenize( ",", tokens ); if ( tokens.size() != 2 ) return false; OCTET_JOIN_BYTE( 4, 1, &aZ_S ); for ( vector<CvString>::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr ) { String decoded; CvBase64::Decode( *itr, decoded ); if ( decoded.size() != FS ) return false; OCTET_JOIN_BYTES( decoded.data(), FS, &aZ_S ); } return true; }
bool CvSakke::DecodePrivateKey( const String& aPrivateKey, OUT octet& aKbS ) { CMiracl miracl( m_sakkeDomain ); OCTET_CLEAR(&aKbS); if ( aPrivateKey[0] != '[' || aPrivateKey[aPrivateKey.length()-1] != ']' ) return false; CvString privateKey = aPrivateKey; privateKey.TrimLeft( "[" ); privateKey.TrimRight( "]" ); vector<CvString> tokens; privateKey.Tokenize( ",", tokens ); if ( tokens.size() != 4 ) return false; Big xx, xy, yx, yy; Big* pBigs[] = { &xx, &xy, &yx, &yy }; int i = 0; for ( vector<CvString>::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr, ++i ) { String decoded; CvBase64::Decode( *itr, decoded ); bytes_to_big( _MIPP_ (int)decoded.size(), decoded.data(), pBigs[i]->getbig() ); } ZZn2 x( xx, xy ); ZZn2 y( yx, yy ); aKbS.len = 4*FS; big_to_bytes( _MIPP_ FS, x.getzzn2()->a, &aKbS.val[0], TRUE ); big_to_bytes( _MIPP_ FS, x.getzzn2()->b, &aKbS.val[FS], TRUE); big_to_bytes( _MIPP_ FS, y.getzzn2()->a, &aKbS.val[2*FS], TRUE); big_to_bytes( _MIPP_ FS, y.getzzn2()->b, &aKbS.val[3*FS], TRUE); return true; }