This is a question that can only really be answered by a lawyer familiar with your circumstances and the laws in your jurisdiction. For example, by default, in Canada, if you're hired as a contractor to produce a work, you retain the copyright on that work (or so I was taught in my 100-level Business Law class). However, I don't believe this is true in the US. It's also not true in either country if you're hired as a salaried employee.
But really, plenty of other people will be offering legal advice, and the reality is that this matter won't go to court because it's not worth the time or money for you or the university. You can get a lawyer's opinion that you're in the clear to release your work, but even that's only so helpful to you -- if you threaten or bully your employer, that may just set them against you. (On the other hand, it may be just the thing! Maybe they need to see that you won't be pushed around. Different people respond to different tactics.)
The most elegant solution to your problem is politics. Convince your boss's boss and your boss's respected colleagues that your work would be better off shared -- people's opinions are ultimately derived from the opinions of the people they respect. You've made good use of an open-source base, right? Make sure they understand that there's value in tapping into that community. Allay their fears. Show them the positive side. Get people on your side.
If you can swing this right, it won't matter what the legalities are because the one of the university's officers will sign a waiver disclaiming interest in the code and you'll be in the clear for sure -- and your boss will be pleased at having done something good.
Sure, you should have got the signature before you started working; then you wouldn't have to spend cycles on this problem. Still, it may be fixable.
And if that doesn't work, just remember: the implementation is twice as good and ten times as quick to write when you've done it once before!