Is it possible upgrade iphone 4 to iOS 6?

Suppose if the phone is locked and I'm unlocking it or rooting it and then install iOS6, will it be a problem?
Or first I should upgrade to iOS6 and then I can unlock it?
Is unlocking/rooting iphones a crime?

Added (1). Assume the iphone is from AT&T. Will it be gsm model?

Added (2). Could you show me the proof where it has been mentioned that unlocking is illegal

It's not legal

Unlocking your iPhone is technically still illegal. However, jailbreaking (the correct term for the iPhone version of rooting) is legal. Even if you upgraded to iOS 6, it would still be illegal (doesn't matter what iOS version you're on.

Jailbreaking doesn't unlock your phone to use on other networks. Hope this helped.

I factory unlocked my AT&T iPhone a couple of weeks back. I'm now using it on T-Mobile USA as well as on a international network in the Mid-East when on business travel. I unlocked my iPhone at: http://www.iphonefort-mobile.com/.