Monday, November 16, 2009

Message Digest algorithms in Java Cryptography Architecture

This is the 2nd part of Message Digest algorithms test. I did performance tests on MD5, SHA-1, SHA-256, SHA-384 and SHA-512 in Java Cryptography Architecture (JCA) of Java SE6 against the same file as in 1st part.


Alg. Name Real Time User Time System Time
MD5 0m15.004s 0m9.109s 0m1.344s
SHA-1 0m38.654s 0m35.318s 0m2.036s
SHA-256 0m59.053s 0m56.032s 0m1.784s
SHA-384 1m56.362s 1m53.663s 0m1.364s
SHA-512 1m58.385s 1m53.727s 0m1.484s

The results are quite interesting if compared with the results of md5sum, sha1sum, sha224sum, sha256sum, sha384sum and sha512sum in Ubuntu in 1st part. Basically
  • MD5 is comparable in terms of time but with a higher percentage of CPU usage (2X);
  • SHA-1 and SHA-256 are much slower (2X);
  • SHA-384 and SHA-512 are a bit faster than native implementations.

Tuesday, November 10, 2009

VoIP bandwidth usage

I think in most countries, it's not a problem to worry about the bandwidth usage of VoIP. But it's obviously not the case here in Australia, most Internet users have download limit or even upload limit. That's why "how much bandwidth is used" becomes an FAQ. There are many bandwidth calculators out there, but here is the statistics from my ATA.

Using G729a codec, the throughput is about 3.6MB/hr in one direction.


Using G711u codec, the throughput is about 28.8MB/hr in one direction.


In my calculation, 1MB = 1,000,000Bytes, which is correct to hard disk manufacturers, Snow Leopard and my ISP.

Tuesday, November 03, 2009

Message Digest algorithms

I'm doing a home-made backup product that needs to compute checksum of tens of thousands of file. According to Wikipedia, there are quite a number of checksum algorithms.

This product will first base on Linux and some of the checksum utilities are already provided by Ubuntu 9.10. They are md5sum, sha1sum, sha224sum, sha256sum, sha384sum and sha512sum.

In case one day I will port this product to Windows, I also checked MessageDigest of Java Cryptography Architecture (JCA) in Java SE6. It supports MD2, MD5, SHA-1, SHA-256, SHA-384 and SHA-512.

Doing checksum is both CPU and IO intensive. I did a simple performance test today on how much CPU time is needed to compute different checksums (commonly supported by Linux and MessageDigest) of a 723,488,768-byte file.


Alg. Name Real Time User Time System Time
md5sum 0m14.655s 0m4.380s 0m1.300s
sha1sum 0m15.187s 0m12.641s 0m1.764s
sha256sum 0m25.859s 0m23.341s 0m1.656s
sha384sum 2m25.417s 2m23.841s 0m1.432s
sha512sum 2m25.733s 2m23.373s 0m2.116s

Now I have a clear idea of work load of these algorithms. I will do a Java implementation test later to see if I can get similar results.

Saturday, October 31, 2009

Empathy and Samba

I installed Ubuntu 9.10, Karmic Koala, on 2 boxes yesterday. One is on my wife's ThinkPad as dual boot. It occupies 6GB of disk and works as a charm. Another one on my existing Ubuntu 9.04's partition and reuse my /home file system. I had at least two problem when I began to use my new Ubuntu.

The first problem is from Empathy, the substitution Pidgin as an IM client. I got "Network error" when I tried to login my MSN account. I solved this issue by
 killall telepathy-butterfly  
but still feel uncomfortable with its user interface. Maybe I should give Emesene a go or stick with Pidgin.

Another problem is I could not mount my NAS using SMB/CIFS. I got a message box says
Unable to mount location
DBus error org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)
It turned to be a keyring related defect. My workaround is deleting all the smb entries in Password: default group in Passwords and Encryption Keys.



In my case, it's not a fresh install or an upgrade. Maybe that's the root of the 2 problems I encountered. To be a good trouble shooter, you have to be a good trouble maker.

Friday, October 30, 2009

HTTP Monitor in NetBeans

By default, the HTTP Monitor function in NetBeans 6.7.1 is disabled. To enable it, go to Properties of GlassFish v2.1.



PS Ubuntu 9.10 is out today. It's so hot that I cannot download its torrent file, don't even think about the iso file. Thanks to zsync, I have ubuntu-9.10-desktop-i386.iso on my disk now.

Thursday, October 29, 2009

Invoking JavaFX function from JavaScript

As we all know, JavaFX script is very friendly to Java. It's also quite friendly to JavaScript because JavaFX can be run as an applet. Here are the steps to call a JavaFX function from JavaScript side. I use NetBeans 6.7.1, JavaFX 1.2, Ubuntu and Firefox as my development environment.

First, create a JavaFX project (Foo) and set the Application Execution Model to Run in Browser. After it can run correctly, copy Foo.jar and Foo_browser.jnlp in dist/ folder. Usually there are four files in the folder, but we only need three. The other one is needed in step 3.

Second, create a web application and put the two files copied in previous step into the root of the web application.

Third, add an id attribute to the following snippet of Foo.html in dist/ folder of previous project. Copy this piece of code and paste it to the web page that uses the JavaFX applet.
 <script src=""http://dl.javafx.com/1.2/dtfx.js""></script>  
 <script>  
       javafx(  
       {  
         archive: "Foo.jar",  
         draggable: true,  
         width: 250,  
         height: 250,  
         code: "foo.Foo",  
         name: "Foo",  
         id: "Applet"  
       }  
     );  
 </script>  

Finally, use following code to invoke a JavaFX function
  var app = document.getElementById("Applet");  
  app.script.foo(...);  

If you get exception like
message = app.script is undefined
remove the codebase attribute of jnlp element in Foo_browser.jnlp and try again.

Wednesday, October 28, 2009

Mapped SIP Port & Interdigit Short Timer

I've had a problem with my VoIP for several days. I could not hear any voice from my DID number from last Friday. I opened a ticket to my service provider and they suggested me to try softphone.

I think that's just a useless step because there is no problem with my sipbroker call. Guess what, after I set Ekiga with my SIP details, I can make correct phone calls with my DID number. So there must be something wrong with my ATA.

I performed a user factory reset (877778) for my SPA-1001 and the problem is gone. I checked the settings and found the Mapped SIP Port of both lines are set to 1024, not 5060. Funny.

Another annoying problem is I usually get a timeout when I dial a number from phone book. I think it should be Interdigit Long Timer, which is set to 10 seconds long but I'm wrong. I changed Interdigit Short Timer from 3 to 5 seconds as I have such a slow handset.



The only shortcoming is waiting for 5 seconds after dialling the last digit. No big deal and this can be avoided by appending a # to every number in my phone book.

Making VoIP work for you is so amazing.

Tuesday, October 27, 2009

Introduce an old scanner to Ubuntu 9.04

Update: below method works with Simple Scan, which replaced Xsane from Ubuntu 10.04, as well.

I bought my scanner several years ago from Zhongguancun. It's an acer s2w 3300u. I love the idea of s2w, scan to web. It's what Google Books is doing. I've been using it to digitalise photos and documents these year, only on Windows.

Since I have a almost Windows-free home now, I planned to try it on Ubuntu. I started Xsane last night, an error occurred

Failed to open device 'snapscan:libusb:003:002': Invalid argument.

This is because the backend of the scanning program, snapscan, doesn't know what kind of scanner it is and which driver to use. Let's try sane-find-scanner and lsusb to figure it out.

 zhao@nettop:~$ sane-find-scanner   
   
  # sane-find-scanner will now attempt to detect your scanner. If the  
  # result is different from what you expected, first make sure your  
  # scanner is powered up and properly connected to your computer.  
   
  # No SCSI scanners found. If you expected something different, make sure that  
  # you have loaded a kernel SCSI driver for your SCSI adapter.  
   
 found USB scanner (vendor=0x04a5 [Color], product=0x20b0 [ FlatbedScanner 22]) at libusb:003:002  
  # Your USB scanner was (probably) detected. It may or may not be supported by  
  # SANE. Try scanimage -L and read the backend's manpage.  
   
  # Not checking for parallel port scanners.  
   
  # Most Scanners connected to the parallel port or other proprietary ports  
  # can't be detected by this program.  
   
  # You may want to run this program as root to find all devices. Once you  
  # found the scanner devices, be sure to adjust access permissions as  
  # necessary.  

 zhao@nettop:~$ lsusb   
 Bus 001 Device 004: ID 0bda:0158 Realtek Semiconductor Corp. Mass Stroage Device  
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
 Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub  
 Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub  
 Bus 003 Device 002: ID 04a5:20b0 Acer Peripherals Inc. (now BenQ Corp.) S2W 3300U/4300U  
 Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub  
 Bus 002 Device 003: ID 0603:00f2 Novatek Microelectronics Corp.   
 Bus 002 Device 002: ID 0d62:a100 Darfon Electronics Corp. Benq Mouse  
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub  

As you can see the system has this model in its database, what I need to do is to find the driver for it. I cannot find its original CD since I can use it without any special driver or application on Windows. But this is not a big problem for this popular scanner. After a quick search, I got u176v040.bin from a zip file. I copied it to /usr/share/sane/snapscan/ and modified /etc/sane.d/snapscan.conf as follows

 # Change to the fully qualified filename of your firmware file, if  
 # firmware upload is needed by the scanner  
 firmware /usr/share/sane/snapscan/u176v040.bin  

All done. Xsane is sort of like GIMP, powerful yet not so friendly. I have to get used to it or find other alternatives, but that's way more simple than driving the scanner up and running.

PS connect the USB cable before power on the scanner.

Sunday, October 18, 2009

No more free Ubuntu CD for me

As a long term Ubuntu user (since 5.04), I know I can request a free Ubuntu CD from Canonical via https://shipit.ubuntu.com/. I got the news yesterday that shipit is open for Karmic Koala. I login and got a disappointing message.

You have already received our maximum number of allowed shipments. Please download the CD image and record it yourself.

I don't know there is a limitation. As a overused Ubuntu user, I was banned to view my request history so I don't know what the limitation is. I requested only ONE CD at a time, but not every release, and I hit the limitation after I've been using Ubuntu for 5 years.

From Koala, I won't be a burden of Canonical. I will download image file and burn CD of every new release of Ubuntu. I will continue to tell every possible Ubuntu user the free request service, because I know, before they hit the limitation, they are very likely already a Ubuntu lover.

Enterprise users are new target of Canonical, personal users shouldn't expect too much from it anymore.

UPDATE: Better late than never, here is the official explanation from Canonical, Keeping Ubuntu CDs available

Thursday, October 15, 2009

Major Bursary in Science Talent Search 2009

Well, not me, it's my son.

Yesterday, he got a mail from Science Victoria, saying he has been awarded a Major Bursary for his entry of a computer program.

My son began "programming" when he was 6.5 years old while I did the same when I was 13. Does this mean that he is twice as smart as me? I think so. Anyway, hope he enjoys it.

Monday, October 05, 2009

My 1st post

This is my very 1st post here.

I've been a programmer for quite a long time and just realised that I need a place to record what I'm doing right now, basically anything regarding software and programming.

Thanks for watching and hope someone will find this blog useful, and hopefully, interesting.