Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ninjeff
Jan 19, 2004

zootm posted:

I don't disagree with that in general but due to Java's general suckiness, passing in a dynamic value like this as a parameter is non-trivial. Unless you want to pass in an implementation of some obscene interface called BlockDispersalCalculator or something, you're stuck. It is a language limitation though, what you suggest is generally sensible.

Not that this is relevant to the whole "scripting vs hardcoded" discussion, but in this case (determining how many items drop from a block) it seemslike you could just have a minimum and maximum count for each block type and that would cover every reasonable case.

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.

Ugg boots posted:

Correct me if I'm wrong, but by passing in a dynamic value you don't mean passing in an enum value do you?
I mean a value that can change on subsequent calls (i.e. a value defined by a function, rather than a simple value).

Having said that ninjeff's suggestion (which I would quote if I wasn't on a mobile phone) above makes perfect sense assuming people don't want to screw with the distribution.

shrughes
Oct 11, 2008

(call/cc call/cc)
What's the output of this program on your system?

code:
#include <iostream>
#include <map>

int cnt = 0;
struct F {
    ~F() { cnt++; }
};


int main() {
    std::map<int, F> m;
    m[5] = F();
    m.erase(5);
    std::cout << cnt << std::endl;
}
On mine, it's 4.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

shrughes posted:

What's the output of this program on your system?

On mine, it's 4.
Should be 4 on any standards-compliant compiler; what number were you expecting?

ToxicFrog
Apr 26, 2008


^^ Why is that? Shouldn't only one F be created, and thus, only one destroyed?

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

ToxicFrog posted:

^^ Why is that? Shouldn't only one F be created, and thus, only one destroyed?

If map::operator[] is called with a missing key, it automatically inserts a default value with that key before returning its reference. Inserting requires construction of a std::pair<int, F>. The behavior should be something like:

1. call map::operator[] , it constructs a temporary pair, inserts it, then unstacks the temp values (two F deletions)

2. temporary F is created, then assigned to reference returned from operator[], then unstacks the temporary (third F deletion)

3. map::erase() removes the value from the map (fourth F deletion)

shrughes
Oct 11, 2008

(call/cc call/cc)

Janin posted:

Should be 4 on any standards-compliant compiler; what number were you expecting?

I would expect it to be 2. One for the std::pair field on a tree node, and one for the temporary in main(). There's no reason for it to be higher. (And if the standard says it must be identical to m.insert(make_pair(5, F())).first->second then the standard is a coding horror.)

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

shrughes posted:

I would expect it to be 2. There's no reason for it to be higher. (And if the standard says it must be identical to m.insert(make_pair(5, F())).first->second then the standard is a coding horror.)
man, considering the vast and ever-expanding list of horrors that is C++, it's just not worth getting worked up over a few extra data copies.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
One gets created when evaluating the RHS of the assignment; another gets created when evaluating the LHS of the assignment (i.e., creating an object to assign into). It's not possible to elide copy-assignments, so that's the bare minimum.

libstdc++'s std::map requires two more temporaries because it actually implements operator[] in terms of insert(it, value_type(key, mapped_type())) when the key isn't found, which creates a temporary key and *two* temporary values.

EDIT: beaten quite badly.

ohgodwhat
Aug 6, 2005

http://sourcesale.com/projects/2357-Encryption-Static-Library

I haven't seen the source code for it, but the description is bad enough. This is supposed to be a form of encryption?

quote:

The library gets a password from an array and uses it to create a much bigger array. Then it gets a byte from the data to be encrypted and adds that with a value within the larger array. To use this for file encryption I recommend using the while loop and loop through the file sending data to the library one byte at a time until the file ends.

POKEMAN SAM
Jul 8, 2004

ryanmfw posted:

http://sourcesale.com/projects/2357-Encryption-Static-Library

I haven't seen the source code for it, but the description is bad enough. This is supposed to be a form of encryption?

Hah, that's awesome. Here's a preview of the code from that page :D

code:
  dat -  keytemp[keycount];
    keycount += 1;
	if (keycount > 1048576) {
		keycount = 1;
	}

return dat;
}




}


/////////////////////////////////////////////////////////////////////////////////////

void keygenerate() //calculates keytemp 
{
	extern unsigned short int passtemp[512];	//refers to passtemp in program

gibbed
Apr 10, 2006

Ugg boots posted:

Hah, that's awesome. Here's a preview of the code from that page :D
I RE'd a little bit of the testalib.exe and it appeared to just be XORing the content with a generated table based on the key (this is just from a quick look though, I could be wrong). So yeah, crappy obfuscation.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

gibbed posted:

I RE'd a little bit of the testalib.exe and it appeared to just be XORing the content with a generated table based on the key (this is just from a quick look though, I could be wrong). So yeah, crappy obfuscation.

That's how AES-CTR and AES-OFB work, except the table is so fantastically large it's impractical to store.

Scaevolus
Apr 16, 2007

BonzoESC posted:

That's how AES-CTR and AES-OFB work, except the table is so fantastically large it's impractical to store.
Yes, stream ciphers work by XOR-ing a suitably random stream of bits with a message stream.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
mysql> select aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy');
+-------------------------------------------------------------------------------------+
| aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy') |
+-------------------------------------------------------------------------------------+
|                                                                                   1 |
+-------------------------------------------------------------------------------------+


http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.5/view/head:/mysys/my_aes.c

Opinion Haver
Apr 9, 2007

Aleksei Vasiliev posted:

mysql> select aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy');
+-------------------------------------------------------------------------------------+
| aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy') |
+-------------------------------------------------------------------------------------+
|                                                                                   1 |
+-------------------------------------------------------------------------------------+


http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.5/view/head:/mysys/my_aes.c

I don't get it.

vvv oh, hurr.

Opinion Haver fucked around with this message at 01:37 on Feb 23, 2011

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

Aleksei Vasiliev posted:

mysql> select aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy');
+-------------------------------------------------------------------------------------+
| aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy') |
+-------------------------------------------------------------------------------------+
|                                                                                   1 |
+-------------------------------------------------------------------------------------+


http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.5/view/head:/mysys/my_aes.c

Is that a case of an accidental collision, or a pre-defined default key?

yaoi prophet posted:

I don't get it
it means that encrypting something with '4re35na2aTaVasAy4re35na2aTaVasAy' as a key has the same result as not using a key at all.

bobthecheese fucked around with this message at 01:25 on Feb 23, 2011

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

bobthecheese posted:

Is that a case of an accidental collision, or a pre-defined default key?
If the key length is >128 bits, MySQL reduces it by XOR. "4re35na2aTaVasAy4re35na2aTaVasAy" is just "4re35na2aTaVasAy" twice, so it reduces to 0 (the same as ""). You can get the same result by doubling (or quadrupling, etc) any 16-character string.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

Janin posted:

If the key length is >128 bits, MySQL reduces it by XOR. "4re35na2aTaVasAy4re35na2aTaVasAy" is just "4re35na2aTaVasAy" twice, so it reduces to 0 (the same as ""). You can get the same result by doubling (or quadrupling, etc) any 16-character string.

Oh, wow, that IS a horror.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I can't wait for Oracle to finally kill MySQL

Kelson
Jan 23, 2005

Aleksei Vasiliev posted:

mysql> select aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy');
+-------------------------------------------------------------------------------------+
| aes_encrypt('hello', '') = aes_encrypt('hello', '4re35na2aTaVasAy4re35na2aTaVasAy') |
+-------------------------------------------------------------------------------------+
|                                                                                   1 |
+-------------------------------------------------------------------------------------+


http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.5/view/head:/mysys/my_aes.c
I'm not sure I'm following where that value arises from the link. In my_aes_create_key, I see that it leaves rkey 0'd out if key_length is 0, but it looks like rijndaelKeySetup* (wherever that's defined) then sets "4re...". Am I missing something?

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Kelson posted:

I'm not sure I'm following where that value arises from the link. In my_aes_create_key, I see that it leaves rkey 0'd out if key_length is 0, but it looks like rijndaelKeySetup* (wherever that's defined) then sets "4re...". Am I missing something?
read my post

Kelson
Jan 23, 2005

Janin posted:

read my post
I did. I didn't say "I don't understand what is happening". Instead, "I'm not following where that value arises from the link."

gibbed
Apr 10, 2006

BonzoESC posted:

That's how AES-CTR and AES-OFB work, except the table is so fantastically large it's impractical to store.
Well yes, but this self-implemented junk is terrible.

POKEMAN SAM
Jul 8, 2004

gibbed posted:

Well yes, but this self-implemented junk is terrible.

It's like, yeah I kinda know how hash functions work, but I sure as poo poo won't try to write one myself!

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Kelson posted:

I did. I didn't say "I don't understand what is happening". Instead, "I'm not following where that value arises from the link."


code:
  for (ptr= rkey, sptr= key; sptr < key_end; ptr++,sptr++)
  {
    if (ptr == rkey_end)
      ptr= rkey;  /*  Just loop over tmp_key until we used all key */
    *ptr^= (uint8) *sptr;
  }

Kelson
Jan 23, 2005

Ryouga Inverse posted:

code:
  for (ptr= rkey, sptr= key; sptr < key_end; ptr++,sptr++)
  {
    if (ptr == rkey_end)
      ptr= rkey;  /*  Just loop over tmp_key until we used all key */
    *ptr^= (uint8) *sptr;
  }
That's what I thought at first, except key_length is presumably 0 for the empty string. That means key_end = key + 0, which is really just key. Which skips the for(sptr = key;sptr < key;sptr++) loop?

If that weren't the case, the value would be whatever happened to be in the "invalid" memory block key pointed towards (which may change between runs).

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Kelson posted:

That's what I thought at first, except key_length is presumably 0 for the empty string. That means key_end = key + 0, which is really just key. Which skips the for(sptr = key;sptr < key;sptr++) loop?

If that weren't the case, the value would be whatever happened to be in the "invalid" memory block key pointed towards (which may change between runs).

Correct, except the memory block isn't invalid in that case, it's explicitly initialized to zero by the bzero call prior to the block.

The value Aleksei Vasiliev chose doesn't come from the code, it's arbitrary. It just happens to have the property that when XORed over itself in 16-byte chunks it becomes zero. The key "4re35na2aTaVasAy4re35na2aTaVasAy" is the same as the key "" is the same as the key "0123456789abcdef0123456789abcdef" is the same as the key "abcdefghijklmnopabcdefghijklmnop" is the same as the key "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb" and so on and so on.

ShoulderDaemon fucked around with this message at 04:35 on Feb 24, 2011

Kelson
Jan 23, 2005

ShoulderDaemon posted:

Correct, except the memory block isn't invalid in that case, it's explicitly initialized to zero by the bzero call prior to the block.
Really?

code:
static int my_aes_create_key(KEYINSTANCE *aes_key, enum encrypt_dir direction, const char *key, int key_length)
{
  uint8 rkey[AES_KEY_LENGTH/8];	 /* The real key to be used for encryption */
  uint8 *rkey_end=rkey+AES_KEY_LENGTH/8; /* Real key boundary */
  uint8 *ptr;			/* Start of the real key*/
  const char *sptr;			/* Start of the working key */
  const char *key_end=key+key_length;	/* Working key boundary*/
  bzero((char*) rkey,AES_KEY_LENGTH/8);      /* Set initial key  */

  for (ptr= rkey, sptr= key; sptr < key_end; ptr++,sptr++)
  {
    if (ptr == rkey_end)
      ptr= rkey;  /*  Just loop over tmp_key until we used all key */
    *ptr^= (uint8) *sptr;
  }
  ...
}
If key_length is 0, the for loop never executes (no xor takes place in my_aes_create_key) which leaves rkey bzero'd. If mysql was retarded and key_length somehow weren't 0 in the empty-key instance above, it'd xor *sptr into rkey, which is "invalid" memory (sptr = key; sptr < key+key_length) not the bzero'd buffer (ptr = rkey; bzero(rkey, AES_KEY_LENGTH/8)).

ShoulderDaemon posted:

The value Aleksei Vasiliev chose doesn't come from the code, it's arbitrary. It just happens to have the property that when XORed over itself in 16-byte chunks it becomes zero. The key "4re35na2aTaVasAy4re35na2aTaVasAy" is the same as the key "" is the same as the key "0123456789abcdef0123456789abcdef" is the same as the key "abcdefghijklmnopabcdefghijklmnop" is the same as the key "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb" and so on and so on.
I believe "4re35na2aTaVasAy" is xor'd into each 16-byte chunk; where is that value in the code above? I may certainly be missing something, I'm just asking what. It appears to be in code not shown in the link (such as within rijndaelKeySetupEnc(aes_key->rk, rkey, AES_KEY_LENGTH)). No?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
*key is a pointer to the password
rkey is an array of length 16 (AES_KEY_LENGTH = 128, /8 = 16. see my_aes.h for the define)
rkey is the actual key that will be used to encrypt/decrypt

  for (ptr= rkey, sptr= key; sptr < key_end; ptr++,sptr++)
  {
    if (ptr == rkey_end)
      ptr= rkey;  /*  Just loop over tmp_key until we used all key */
    *ptr^= (uint8) *sptr;
  }


sptr = the password pointer

it first zeroes the realkey, if the given password is 0-length then it's done creating the realkey, the loop doesn't run

if not, then it will iterate through the realkey[16] for as many bytes as there are in the password, XORing as it goes. that's this line: *ptr^= (uint8) *sptr;.( ^= is XOR-assignment). if it hits the realkey's end, then it will reset to the beginning of the array. the password index is not changed.

did this help


(also I'm a Java programmer so my explanation might be totally wrong :v: )

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I don't see what the problem is. Just use "4re35na2aTaVasAy4re35na2aTaVasAy4re35na2aTaVasAy" and you'll be fine. :eng101:

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Kelson posted:

If key_length is 0, the for loop never executes (no xor takes place in my_aes_create_key) which leaves rkey bzero'd.
Correct.

Kelson posted:

If mysql was retarded and key_length somehow weren't 0 in the empty-key instance above, it'd xor *sptr into rkey, which is "invalid" memory (sptr = key; sptr < key+key_length) not the bzero'd buffer (ptr = rkey; bzero(rkey, AES_KEY_LENGTH/8)).
This does not happen; key_length is zero in the empty-key instance.

Kelson posted:

I believe "4re35na2aTaVasAy" is xor'd into each 16-byte chunk; where is that value in the code above?
Incorrect. The "4re35na2aTaVasAy" is not an artifact of the code, it's just something Aleksei Vasiliev chose arbitrarily. "4re35na2aTaVasAy" is not special.

The only thing that's special about about the key that Aleksei Vasiliev chose is that it consists of a 16-character string, repeated an even number of times. Any such key will be equivalent to the all-zeroes key or the empty key.

Kelson posted:

I may certainly be missing something, I'm just asking what. It appears to be in code not shown in the link (such as within rijndaelKeySetupEnc(aes_key->rk, rkey, AES_KEY_LENGTH)). No?

Nowhere within any of the MySQL code or its support libraries will you find "4re35na2aTaVasAy". It's not a value that comes from the code. It's just a value that Aleksei Vasiliev picked to demonstrate the problem.

Opinion Haver
Apr 9, 2007

code:
mysql> select aes_encrypt('hello', '') = aes_encrypt('hello', 'arbitrarypasswrdarbitrarypasswrd');
+-------------------------------------------------------------------------------------+
| aes_encrypt('hello', '') = aes_encrypt('hello', 'arbitrarypasswrdarbitrarypasswrd') |
+-------------------------------------------------------------------------------------+
|                                                                                   1 |
+-------------------------------------------------------------------------------------+
See?

NotShadowStar
Sep 20, 2000
Sheet nigga, that's all you had to say!

Randomosity
Sep 21, 2003
My stalker WAS watching me...

ToxicFrog posted:

Who the gently caress uses floats to store monetary amounts :psyduck:

At the risk of sounding stupid, what's that preferred way?

VVV hah, I understand how floats are stored and their implicit fuzziness. I meant which variable type or some other method.

Randomosity fucked around with this message at 19:57 on Feb 24, 2011

pseudorandom name
May 6, 2007

Certainly not a format incapable of storing exact values.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Store an integer containing cents; doubles are just big floats.

Incoherence
May 22, 2004

POYO AND TEAR

rt4 posted:

Store an integer containing cents; doubles are just big floats.
[insert Office Space plot summary here]

dis astranagant
Dec 14, 2006

Randomosity posted:

At the risk of sounding stupid, what's that preferred way?

VVV hah, I understand how floats are stored and their implicit fuzziness. I meant which variable type or some other method.

There are decimal data types in many languages and the ones that don't probably have a library for it. Anyone working with money should probably use them (especially if they could be audited).

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

That's not how aes_encrypt works, though. It expects to get a (random) 128-bit string.

It should probably be noted in the documentation, but I don't see how this is a horror.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply