A Random Thought

Hi there!
It’s been forever!

This blog of mine has been abandoned for centuries long, yeah, I know. My bad.
So… A lot of things had happened during these times.
Good things, and of course, bad things.
In a 24-hour-times, life could be upside down. And you would never have a clue of how life would turn out to be.

Life has been tiring lately. I’m just weary, in a state of devastated, and literally broken.
As expected, overcoming pain and growing up is definitely not an easy task to do.
Guess I need some guidance. Any of you?

And by the way, sorry for my rant.
See you in my next post.

Pop Quiz, hot shot. How would you write code to shuffle a deck of cards?

sLet’s assume we have an array with 52 members representing the 52 cards in the deck.

var rand = new Random();
for (int i = cards.Length – 1; i > 0; i–)
{
int n = rand.Next(i + 1);
int temp = cards[i];
cards[i] = cards[n];
cards[n] = temp;
}

So we loop through the deck, switching each card with another card from a random position in the deck. Seems straightforward enough, although I do wish there was a built in Swap command in the C# language to simplify the code a bit. It’s eerily similar to the Knuth or Fisher-Yates shuffle, which doesn’t mean I’m particularly smart, but that shuffling is an easily solved problem.

Or is it? This looks correct; there’s nothing obviously wrong here. But there are two problems with this code. Can you see them?

The first problem is right here:

new Random();

Computers are lousy random number generators. Any shuffling you do, whatever the algorithm, will only be as good as your random number generator. So if you’re running, say, an online casino, you need to be very careful when you start throwing around the word “Random” in your code. If you aren’t careful, there will be.. problems.

The flaw exists in the card shuffling algorithm used to generate each deck. Ironically, the code was publicly displayed at http://www.planetpoker.com/ppfaq.htm with the idea of showing how fair the game is to interested players (the relevant question has since been removed). In the code, a call to randomize() is included to produce a random deck before each deck is generated. The implementation, built with Delphi 4 (a Pascal IDE), seeds the random number generator with the number of milliseconds since midnight according to the system clock. That means the output of the random number generator is easily predicted. A predictable “random number generator” is a very serious security problem.

By synchronizing our clock with the clock on the online casino and hitting the “shuffle” button, our program can calculate the exact shuffle. That means we know all the cards that have yet to appear, everyone’s hand, and who will win. The screen shot below shows the information displayed by our program in realtime during an actual game. Our program knows what cards are to appear in advance, before they are revealed by the online game.

To be fair, this was 1999. I’d assume most online casinos have hired competent cryptographers and statisticians by now. With the ever looming specter of insider cheating and poker bots, they’d be fools not to.

The second problem with this code is that it’s too complicated. Eric “purplicious” Lippert explains why, in his own inimitable way:

The standard way of implementing this algorithm is: associate each card with a random real number between 0.0 and 1.0. Sort the list based on its associated number. That’s O(n log n) and has no bias.

As it turns out, the easiest way to implement a shuffle is by sorting. It’s not exactly faster, as the typical sort is O(n log n) compared to the O(n) of the Knuth Fisher-Yates shuffle algorithm. We’ll just sort by a random number– in this case, a GUID.

var cards = Enumerable.Range(0, 51);
var shuffledcards = cards.OrderBy(a => Guid.NewGuid());

So we can ultimately implement a secure, unbiased shuffle as a one-liner in a modern programming language.

Conventional Cryptosystem

Model of Conventional Cryptosystems
The following figure, which is on the next page, illustrates the conventional encryption process. The original “plaintext” is converted into apparently random nonsense, called “ciphertext”. The encryption process consists of an algorithm and a key. The key is a value independent of the plaintext. The algorithm will produce a different output depending on the specific key being used at the time. Changing the key changes the output of the algorithm, i.e., the ciphertext.

Once the ciphertext is produced, it may be transmitted. Upon reception, the ciphertext can be transformed back to the original plaintext by using a decryption algorithm and the same key that was used for encryption.

Model of Conventional Cryptosystem

The security of conventional encryption depends on several factors:

The Encryption Algorithm- It must be powerful enough that it is impractical to decrypt a message on the basis of the ciphertext alon

Conventional Cryptosystem

Conventional Cryptosystem


The intended receiver, in possession of the key is able to invert the transformation
X=Dk (Y)

An opponent, observing Y but not having access to K or X, may attempt to recover X or K or both X and K. It is assumed that the opponent knows the encryption (E) and decryption (D) algorithms. If the opponent is interested in only this particular message, then the focus of the effort is to recover X by generating a plaintext estimate X^. Often, however, the opponent is interested in being able to read future messages as well, in which case an attempt is made to recover K by generating an estimate K^.

Dig into X-800 and RFC 2828!!

X-800 is an extention recommendation of the recommendation X-200 which describes the reference model for Open System Interconnection (OSI). It establishes a framework for coordinating the development of existing and future recommendations for the system interconnection. The objective of OSI is to permit the interconnection of heterogeneous computer systems so that communication between application process may be achieved. At various times, security controls need to be built in order to protect the information exchanged between application processes,but by doing so the cost and time of obtaining and modifying data will be greater than the potential value of the informations.
This recommendation defines the general security related architectural elements for which protection of communication between open system is required. It establishes within the framework of reference model, guidelines and constraints to improve the existing recommendation in order to allow secure communications.

X-800 provides a general description of security services and related mechanisms and defines the positions within the reference model where the services and mechanisms may provide.

The OSI security architecture provides a useful overview of many concepts that take eyes on the mechanisms, services and security attacks which can be described as following :
•    Security Attack        : any action that compromises the security of information owned by somebody including unauthorized reading of a message of file and traffic analysis.
•    Security Mechanism    : any process that designed to detect or preventing a security attack to be held.
•    Security Service    : a process of enhancing / improving the security of data processing system and information exchange between application processes.

In this literature, the term threat and attack are commonly used to have similar definitions but here we try to provide definitions of threat and attack according to RFC 2828 :
•    Threat
A potential violation of security which exist when there is an action or event that could breach security and cause harm.
•    Attack
An intelligent act that is a deliberate attempt to evade security services and violate the security policy of a system.

According to X-800 standards, there are 8 security dimensions addresses to network vulnerability :
1.    Access control  
2.    Authentication
3.    Non – repudiation
4.    Data consistency
5.    Communication security
6.    Data integrity
7.    Avaliabity
8.    Privacy

X.800 defines a security service as a service provided by a protocol layer of communicating open systems, which ensures adequate security of the systems or of data transfers.The following are considered to be the security services which can be provided optionally within the framework of OSI reference model.

1.    Authentication
These services require authentication information compromising locally stored information and data for authenticating.
-. Peer Entity Authentication : this service is provided for use at the establishment or during data transfer phase of a connection to confirm the identities of one or more of the entities connected to one or more of the other entities.
-. Data Origin Authentication : this service provides the corroborations of the source of a data unit, it doesn’t provide protection against duplication or modifications of data units.

2.    Access Control
Provides protection against unauthorized use of the resources accessible via OSI, may be applied to various type of access to a resource.

3.    Data Confidentiality.
Provides the protection of data from unauthorized disclosure using these methods : connection confidentiality, connectionless confidentiality, selective fields confidentiality, traffic flow confidentiality.

4.    Data Integrity
This service counter active threats, at the start of the connection using the peer entity authentication service and the data integrity service during the life of the connection can provide the detection of duplication of data units.

5.    Non – Repudiation
This service is divided into 2 types :
1.    Non – repudiation with proof of origin : the recipient is provided with proof of the origin data , this will protect any attempt by the sender to falsely deny sending the data or its contents.
2.    Non – repudiation with proof of delivery : the sender is provided with proof of delivery, this will protect against any subsequent attempt by recipient to falsely deny receiving the data or its contents.

Specific Security Mechanisms
The following mechanisms may be incorporated into the appropriate layer in order to provide some of the service :
1.    Encipherment
2.    Digital signature mechanism
3.    Access control mechanism
4.    Data integrity mechanism
5.    Authentication exchange mechanism
6.    Traffic padding mechanism
7.    Routing control mechanism
8.    Notarization mechanism

Pervasive Security Mechanisms
This mechanism describes a number of mechanisms which are not specific to any particular service, they are not explicitly described as being in any particular layer but some can be regarded as aspects of security management directly related to the level of security required.
1.    Trusted functionality
2.    Security labels
3.    Event detection
4.    Security audit trail
5.    Security recovery