Showing posts with label crypto. Show all posts
Showing posts with label crypto. Show all posts

05 June 2010

Rijndael S-box Sage implementation

It's no secret I like Python and Sage a lot. Today, I had the pleasure of working with Sage again: as a school assignment, I was required to show the calculations that prove that the value of the Rijndael S-box in row 2, column d, was indeed d8. While I am able to invert a polynome of this size by hand (let alone apply an affine transformation), I see no reason to do it, as a suitable tool is available.

So, here we go, the Rijndael S-box in Sage:

F.<y> = GF(2, name='y')[]
K.<x> = GF(2**8, name='x', modulus=y^8 + y^4 + y^3 + y + 1)

bin_digits = lambda h: [((int(str(h), 16))//(2^i)) % 2
for i in range(3, -1, -1)]
bin_poly = lambda n : sum([b * x^(3-i)
for i,b in enumerate(bin_digits(n))])

b1 = 2
b2 = 'd'

s = x^4 * bin_poly(b1) + bin_poly(b2)
p = (1/s).polynomial().coeffs()
p.reverse()

b = [0]*(8 - len(p)) + p
b.reverse()
c = [1,1,0,0,0,1,1,0]
d = [int((b[i] + b[(i + 4) % 8] + b[(i + 5) % 8] +
b[(i + 6) % 8] + b[(i + 7) % 8] + c[i]).n()) % 2
for
i in range(8)]
d.reverse()

s1 = sum([d[i] * 2^(3-i) for i in range(4)])
s2 = sum([d[i+4] * 2^(3-i) for i in range(4)])

print hex(s1), hex(s2)

I admit: the above is code, not calculations, but I did the calculations in class and worked hard on the code. My main problem was the bit order. Nowhere in the original publication did it say to reverse the bytes. Adding all the reverses was a moment of desperation, and imagine my surprise when it worked. I wonder how much credit that solution will get me.

A great Friday night it was.

06 November 2009

Geek got to teach!

If I haven't been an active blogger lately, that's because something came up. Something that kept me stressed and busy: I lectured the security class on Tuesday.

I lectured! Security! At the University of Warsaw! If you can't believe it, don't worry neither do I.

I talked about what I knew best: mathematical methods of breaking the RSA cipher. I also gave an introduction to elliptic curve cryptography and covered primality tests. Here are the slides (Polish only). Out of 150 people enrolled, some 30-40 were present and the lecture went pretty well: there were questions, I was able to answer... And first of all, what an honor!

18 September 2009

Blogging my thesis

I'm currently in the process of writing my master thesis. Here gos the subject:

Displacement of smooth integers in short intervals and their applications in cryptography

Ain't it the coolest thesis ever?

To be honest, I don't quite see it that way. Anything I want to do inevitably turns into something I have to do. So this post is party a pep talk to myself. I don't think it matters, however: most Fiona Apple's songs are pep talks to herself and boy, do I love them.

Okay, back to the thesis. I will be breaking the RSA cryptosystem. Calm down, your private communication is not in danger. I will not obtain significant results, only a small speed improvement over doing it "the dumb way".

How do you break RSA anyway? The whole idea, is that multiplying two big primes is easy, but having only that result, finding out what the primes were is hard. "The dumb way" is trying all the possible primes. There are some smarter ways, but they only work in specific cases, and the keys used in the real world are wisely chosen, so the tricks don't apply. There's an excellent publication about this called "Twenty years of attacks on the RSA cryptosystem". A great read, and you can skip the formulas if you're not that into maths.

So, I will be factoring big numbers into two big prime factors. To do that, I will be using smooth numbers, which are kinda the opposite of primes: they have plenty of small factors. That part is really easy, and is well explained by Pomerance in his paper "Smooth Numbers and the Quadratic Sieve". The first two pages have it all in elementary language, the later ones are hard even for me.

To find these smooth numbers, I will be comparing three different methods: sieving, the Bernstein method and finding them using error correcting codes based on the Chinese Remainder Theorem.

More on how it goes will (most probably) come.

07 January 2009

Bruce Schneier is coming to Poland!

Bruce Schneier is coming to Poland! He'll be the keynote speaker at CONFidence 2009.


More info about the conference at 2009.confidence.org.pl.

23 December 2008

Big day that started bad

Today was a really big day for me: I decided to start writing my master thesis!

Here's how the title goes:

Displacement of smooth integers in short intervals and their applications in cryptography.
Sounds great, doesn't it?

So. I found the papers with the stuff I needed to start and downloaded the LaTeX template. Didn't compile. Tried compiling a kinda "Hello, World!" document. Didn't compile. Switched computers. Didn't compile.

Started loading The Sims on one of the computers while fighting with MikTex 2.7 on the other one. The Sims would freeze while loading any lot. Started wondering really hard what was going on with the world.

The Sims were easier to fix. I downloaded Sims2Pack Clean Installer, that showed my add-ons by install date, with a red background if they were suspicious. I got them working after a few tries and build something like a dorm that was in fact an apartment lot. Some old guy moved to my so-called dorm, no girl did and the residents would stay in their bedrooms instead of enjoying the kitchen, study, tv room, swimming pool and other cool stuff I prepared for them. Still, doesn't beat the stupidity of the 51 NPCs that moved into that:


Fixing MikTex was harder. Actually, there was no fixing, but getting the 2.5 version from Daddy from two years ago and getting the required packages from some russian ftp server.

But, I wrote my name on the master thesis template, so I have officially started writing it today!

30 October 2008

Yet another math presentation

The geek life has been a bit harder lately. I spent an entire day and then an entire evening preparing a presentation about the Weil Pairing. Don't ask me what it is - I have been trying to understand it for two years! (Well, I have been trying other things as well during those years, but still, you get the idea.)

"Sweetie, I know you're busy, but I gotta ask you one thing: who's the long unseen friend from the previous post?" messaged me Boyfriend. The brief explanation of Long Unseen Friend being an ex of mine didn't really satisfy him, nor the fact that he missed our appointment and still I set a new one.

But let's not allow the boys to distract us from the Weil Pairing, because I have great news! After those two years, I have finally understood what the Weil Pairing is and how to evaluate it! There's a bad news too: I understood it fully during my presentation. I realized that the example I had picked was by far too simple and I still have a lot of work to do. But hey, I finally got it!

For those of you who speak Polish, know a bit of math and aren't easily scared (anyone still reading?), here are my slides:

29 October 2008

A lovely school day

Today was a totally lovely school day.

First I slept until nine. Ate breakfast watching "Lipstick Jungle", showered, read the daily portion of LifeHacker. Ran out of the house afraid to miss the train and had to wait ten minutes. You know, the usual.

School started for me at twelve with a geometry seminar. Just before, I had an "ooops, I forgot I had a blog again" moment and blogged. But back to the seminar, it was really good. The guy was well-prepared, had read a few different sources, understood the subject very well, published the notes... excellent work.

Then a break, during which I got a free coffee (with a mug) from Citibank. Grateful, I decided to honor them with my presence at a case study, which turned out to be a long talk about career opportunities that convinced me that I was already working at the right place, as they were looking for network people and not programmers. I also got a call from a long unseen friend and set up a meeting for tomorrow.

Next came a law class, where I was distracted by the thought of my coming-up presentation about the Weil Pairing. Whatever that is, the fact that I keep getting the n-th power of one instead of a root is highly disturbing. I'm still working on that now that I'm home - and that's how a typical geek day ends.

02 October 2008

Happy new year!

Academic year, that is.

School just started again. I am happily surprised to still see may friends here: many people have graduated, and those who have not only have a few classes so it's hard to meet them at school.

So I met a few good old friends. One lend me money when I lost my wallet (it turned out to be under my laptop) and I made his life better by enlightening him about the white-space css property. One friend gave me my beloved algebra notebook back and I lend her three calculus ones.

Friends are old, but classes are new: law, functional programming, geometry and again, my beloved number theory and cryptography. Next week, I'm having a presentation about the Minkowski addition.

School's cool, but since I started working, I prefer my job much more.

20 June 2008

Not everything is due at midnight.

Today has been another day of gaining life experience and wisdom.

I used to think everything was always due at midnight, unless otherwise stated. The operating systems assignement were due in the morning, which meant sleepless nights. Everything else is always due at midnight, as far as I know.

Today, an economy paper was due. Interdisciplinary and related to our studies. With the team project going like crazy and finals, let's just say that an economy paper is not exactly my main priority, nor has ever been in the 45 given days. (Yes, 45.) I sat to it tonight, at 10 p.m. (Yes, two hours, and it was 45 days.) Well, I did some work before: I chose a subject. Buying DRM-protected music made me wonder wether good protection of the kind can be done, which is crypto, which is related to my studies. So, subject: piracy, because it's so interdisciplinary (crypto, economy, sociology, ethics,...) So, 10 p.m., me logs to the platform and what do I see? It's due at 11 p.m.! Did I panick? Not at all, I didn't have time. I just started writing and produced 6500 characters in one hour. This is easier in Polish as the words are longer, but the thing that really helps is writing on a regular basis, which I do here. Anyway, I wrote my paper without sacrificing more time for it than it deserves (now I really really hope the teacher doesn't read this).

Today was way longer that this and way richer in experiences, but, tomorrow is the correcting codes final exam, so I have to go now. Sleep well and remember that not everything is due at midnight.

04 May 2008

This just in: new great master seminar for the CS major!

My third year of computer science studies is ending soon, which means I have to choose one of about 20 master seminars. I was thinking "Logic, Computational Theory and Cryptography", as it has "crypto" in its name and I take all the courses that have "crypto" in their names. But, logic and computational theory... not really my thing, so I was wondering if there was a seminar about security. After all the crypto-classes in math, it would be great to learn something more practical. However, Boyfriend, who picked his CS master seminar two years ago, said there was no such thing.

So, yesterday, I decided to check what security courses my school offered, and I found this:
Course name: Security and Cryptography - interesting...
Academic year: 2008/2009 - very interesting...
Course type: master seminar - whoah!

Imagine this luck! Two years ago, when I had to choose a math master seminar and took interested in number theory (I finished both number theory courses with the best grades), "Number Theory and Cryptography" was created! (And I got in! Students with better grades have priority, so choosing a seminar doesn't mean you'll attend it yet.) And now, again, the seminar of my dreams appears! How amazing is that!

Now my only concern is to get in. Wish me luck!

18 March 2008

Kernel Hacking again

The second part of working on my kernel module is way harder than I thought it would be. It's the fifth day I've spent doing only this and there are still many things to fix. As for tonight, I have discovered:

  • that rw_locks are spinlocks too
  • a dozen of wrong pointers in my code
  • an undeterministic cipher based on DES
None of the above is a good thing.

Still, no matter how tough things are, I found a few spare minutes this morning to buy a new pair of earrings - does it matter that I bought four pairs last Thursday?

22 January 2008

Bruce Schneier facts

You've all heard the Chuck Norris facts and you're all fed up with them. I recently came across
Bruce Schneier Facts. They're all crypto-related and I've spent hours browsing them.
Here are my favourites:

Bruce Schneier puts the "cry" in "cryptography"

Bruce Schneier uses a different salt for his soup every day.

When Bruce Schneier counts, you can't predict the next number he's going to say.

When Bruce Schneier uses double ROT13 encryption, the ciphertext is totally unbreakable.

Bruce Schneier isn't saying what you think he's saying.

Bruce Schneier mounts chosen-ciphertext attacks without choosing the ciphertext.

Bruce Schneier shaves with Occam's razor.
"Who's this Bruce Schneier anyway?" you might ask. He's a cryptographer and he owns a blog about security. His most famous book is Applied Cryptography, which of course, is on my bookshelf. (Although it's not mine but my friend's, but I'm buying my own as soon as she wishes it back.)

04 December 2007

Meeting with the ABW (NSA equivalent)

I just came back from a meeting with the ABW (Internal Security Agency). I'm enchated and excited as every little kid when he discovers his vocation at the early age of eight and says "I wanna be a agent!" (as well as fireman, policeman, austronaut,... I was gonna be a teacher and a writer, never an agent.). I'm seriously considering applying there. But not today.
The pros: the meeting was with people specializing in cryptology, internet security,... And what do they do? EVERYTHING! Cryptography, cryptoanalysis, testing network protocoles,... just make a wish and do it! The have access to all the newest software! And Arabic teachers! I think ths is a place where I could do exactly what I want and I would be able to change it easily as I change my mind. I'm afraid that companies can't provide so many possibilities.
The con: the giant responsability. I wouldn't exactly want to have the weight of the world on my back, and that's what this kinda work is about. I'm scared!
Scared... But that reminds me of one thing: the only good definition of "courage" I ever heard was in a Disney movie (Princess Diaries). I was: "courage is not the lack of fear, but the conviction that something else is more important than fear". Well, isn't the country's security more important than my fear?
This reminds me of another thing: the movie "Thirteen days", when the guys wish there were some great smart guys that would come and solve the issue... but there are no such guys! Or more precisely, they are those guys! All they can do is do their best. So maybe I am one of the guys? With a solid crypto knowledge and being only able to do my best?
That's how I see working at the ABW: as a vocation. You can't do that for the money (they won't hire you). You can't do that for your own satisfaction (allthrough you get it). You can only do it for the country and doing it means assuming a huge responsability, not going "yahoo! I got a great job!".
Now a more pragmatic point of view. It's a work full time, wich means I won't be able to do it for the next 2,5 years (still in school!). So there's no point in applying now. However, it's something that I am really going to consider in two years. I need time to find that vocation in me (or its lack!) and to consider everything. Meanwhile, it's school, hopefully Google Summer of Code this summer, a part-time job next year, and we'll see the rest in its time.