From ded7c106f5ea7c12aa81c4d286eaecc7dc6564ae Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 7 Dec 2010 21:48:59 +0000 Subject: Use append operator instead of copy --- src/math/numbertheory/point_gfp.cpp | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/math/numbertheory/point_gfp.cpp') diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 8cb40270c..04fde03df 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -479,35 +479,30 @@ SecureVector EC2OSP(const PointGFp& point, byte format) if(format == PointGFp::UNCOMPRESSED) { - SecureVector result(2*p_bytes+1); - result[0] = 4; + SecureVector result; + result.push_back(0x04); + + result += bX; + result += bY; - result.copy(1, &bX[0], p_bytes); - result.copy(p_bytes+1, &bY[0], p_bytes); return result; } else if(format == PointGFp::COMPRESSED) { - SecureVector result(p_bytes+1); - result[0] = 2; - - result.copy(1, &bX[0], bX.size()); + SecureVector result; + result.push_back(0x02 | y.get_bit(0)); - if(y.get_bit(0)) - result[0] |= 1; + result += bX; return result; } else if(format == PointGFp::HYBRID) { - SecureVector result(2*p_bytes+1); - result[0] = 6; - - result.copy(1, &bX[0], bX.size()); - result.copy(p_bytes+1, &bY[0], bY.size()); + SecureVector result; + result.push_back(0x06 | y.get_bit(0)); - if(y.get_bit(0)) - result[0] |= 1; + result += bX; + result += bY; return result; } @@ -556,8 +551,8 @@ PointGFp OS2ECP(const byte data[], size_t data_len, //compressed form x = BigInt::decode(&data[1], data_len - 1); - bool yMod2 = ((pc & 0x01) == 1); - y = decompress_point(yMod2, x, curve); + const bool y_mod_2 = ((pc & 0x01) == 1); + y = decompress_point(y_mod_2, x, curve); } else if(pc == 4) { @@ -575,9 +570,9 @@ PointGFp OS2ECP(const byte data[], size_t data_len, x = BigInt::decode(&data[1], l); y = BigInt::decode(&data[l+1], l); - bool yMod2 = ((pc & 0x01) == 1); + const bool y_mod_2 = ((pc & 0x01) == 1); - if(decompress_point(yMod2, x, curve) != y) + if(decompress_point(y_mod_2, x, curve) != y) throw Illegal_Point("OS2ECP: Decoding error in hybrid format"); } else -- cgit v1.2.3