Hi Alex
On Mon, Nov 17, 2008 at 11:35 PM, Alex Peshkov <peshkoff@...> wrote:
>
> Mark (and others)!
>
> Generic functions that can perform various crypt/hast/etc. will be very much
> needed in FB3. But before starting to write programs - please take into an
> account that it's highly desired (up to required) to be flexible. ....
Hi Alex, don't panic, I am well aware of all that :-) - I've got a
few ideas, but I need to learn to crawl before I can run, so I need
to learn some of these fb implementation basics first. If what I do
never gets into fb tree, it will just be a learning exercise for me.
( but rest assured I am thinking as I tinker).
>
>
> What about other questions:
>
> 1) what makeXXXX functions do you mean here? There is too much of them. Please
> be more specific.
What purpose do the makeXXX functions perform, as distinct to the
evlXXX functions?
I wrote makeEncrypt() makeDecrypt(), by copying another makeXXX
function, they seems to allocate a result object, the resulting
object is calculated again in evlEncrypt() as well. But for instance,
all the other makeXXXX functions seems to know the exact size of their
resulting blob/string, but in my case, that is not quite possible,
although I can determine a max limit (which is what I have done). But
is that right?, and how does that fit with the result type/size object
allocated in evlEncrypt?
>
> 2) As far as I remember, CVT_get_string_ptr() will always convert field
> content to string. Do not think this is what we want for encryption purporse.
I used it to get to the raw data in the string object, and with len,
used that to determine what to encrypt, from the other examples that
seemed to be correct, but thought it best to check it was.
if (value->isText()) {
size_t len = CVT_get_string_ptr(value, &ttype,
&data_temp, NULL, 0, ERR_post);
}
else if (value->isBlob()) {
// stuff for blobs
else {
// handle other types, numerics/dates etc or maybe
error at this stage.
}
So presumably, the if(value->isText()) block will:
a) work for all text character types ?
b) including varchars ?
c) but presumably not text blobs ?
> And once more the question come - what are we crypting? Data on disk? Network
> traffic? Etc?
Currently I am trying a simple step, adding an encrypt and decrypt function:
update test_data set field1 = encrypt('AES128','secretkey', field2) ;
update test_data set field2 = decrypt('AES128','secretkey', field2) ;
thats too simple a name to survive, but basically the functions seem
to be working for string data input at the moment.
>
> 3) A good sample of assigning values can be found in
> ExecuteStatement::fetch().
Thanks, thats what I want, a good example to learn from :-)
But I am not so sure it helps, with fetch() the result types and
values are duplicated from the resultset:
dsc& desc = resultSet->getDesc(i + 1);
....
BLB_move(tdbb, from_desc, to_desc, to);
Whereas I, presumably, want to create a new blob from an existing
blob, the example I was using was:
SysFunctions::evlPad() - which, amongst others also does blobs,
creating a new padded blob from the original
It goes as follows:
static dsc* evlPad(Jrd::thread_db* tdbb,
const SysFunction* function,
Jrd::jrd_nod* args,
Jrd::impure_value* impure)
Create a new blob
....
blb* newBlob = NULL;
if (value1->isBlob() || (value2 && value2->isBlob()))
{
EVL_make_value(tdbb, (value1->isBlob() ? value1 : value2), impure);
impure->vlu_desc.setBlobSubType(value1->getBlobSubType());
impure->vlu_desc.setTextType(ttype);
newBlob = BLB_create(tdbb, tdbb->getRequest()->req_transaction,
&impure->vlu_misc.vlu_bid);
}
Write some data into it.
....
BLB_put_data(tdbb, newBlob, address1, length1);
....
Close it.
BLB_close(tdbb, newBlob);
....
Return it as a result of the evlPad function
return &impure->vlu_desc;
So was that a temporary blob or was it saved in the database? Would
that seem to be the right prototype for me to follow in creating my
new return blob of encrypted data?
Now, I appreciate your busy, but do you mid explaining a little about
the steps in evlPad() above, for instance I don't even know what
impure means, or why its important.
Thanks in advance.
Cheers - Mark
|