Botan  1.11.15
src/lib/pk_pad/emsa_raw/emsa_raw.cpp
Go to the documentation of this file.
00001 /*
00002 * EMSA-Raw
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/internal/pad_utils.h>
00009 #include <botan/emsa_raw.h>
00010 
00011 namespace Botan {
00012 
00013 BOTAN_REGISTER_EMSA_NAMED_NOARGS(EMSA_Raw, "Raw");
00014 
00015 /*
00016 * EMSA-Raw Encode Operation
00017 */
00018 void EMSA_Raw::update(const byte input[], size_t length)
00019    {
00020    message += std::make_pair(input, length);
00021    }
00022 
00023 /*
00024 * Return the raw (unencoded) data
00025 */
00026 secure_vector<byte> EMSA_Raw::raw_data()
00027    {
00028    secure_vector<byte> output;
00029    std::swap(message, output);
00030    return output;
00031    }
00032 
00033 /*
00034 * EMSA-Raw Encode Operation
00035 */
00036 secure_vector<byte> EMSA_Raw::encoding_of(const secure_vector<byte>& msg,
00037                                          size_t,
00038                                          RandomNumberGenerator&)
00039    {
00040    return msg;
00041    }
00042 
00043 /*
00044 * EMSA-Raw Verify Operation
00045 */
00046 bool EMSA_Raw::verify(const secure_vector<byte>& coded,
00047                       const secure_vector<byte>& raw,
00048                       size_t)
00049    {
00050    if(coded.size() == raw.size())
00051       return (coded == raw);
00052 
00053    if(coded.size() > raw.size())
00054       return false;
00055 
00056    // handle zero padding differences
00057    const size_t leading_zeros_expected = raw.size() - coded.size();
00058 
00059    bool same_modulo_leading_zeros = true;
00060 
00061    for(size_t i = 0; i != leading_zeros_expected; ++i)
00062       if(raw[i])
00063          same_modulo_leading_zeros = false;
00064 
00065    if(!same_mem(&coded[0], &raw[leading_zeros_expected], coded.size()))
00066       same_modulo_leading_zeros = false;
00067 
00068    return same_modulo_leading_zeros;
00069    }
00070 
00071 }